CryptoTEE is a unified Rust interface for hardware security modules (TEEs/HSMs) across different platforms. It provides secure key management, cryptographic operations, and HTTP message signatures (RFC 9421) with a consistent API.
- π Hardware Security - Leverage platform TEEs (Apple Secure Enclave, Samsung Knox, Android Keystore)
- π Cross-Platform - Single API works on macOS, iOS, Android, Linux, and Windows
- π RFC 9421 - Built-in HTTP Message Signatures support
- π Key Management - Generate, import, export, and manage cryptographic keys
- π‘οΈ Authentication - Biometric and PIN protection for sensitive operations
- π Extensible - Plugin system for custom functionality
- β‘ Async/Await - Modern async Rust API
- π¦ Pure Rust - Safe, fast, and reliable
[dependencies]
crypto-tee = "0.1"use crypto_tee::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create CryptoTEE instance
let crypto_tee = CryptoTEEBuilder::new().build().await?;
// Generate a hardware-backed key
let key = crypto_tee.generate_key(
"my-signing-key",
KeyOptions {
algorithm: Algorithm::Ed25519,
usage: KeyUsage::SIGN_VERIFY,
hardware_backed: true,
require_auth: false,
..Default::default()
},
).await?;
// Sign data
let signature = crypto_tee.sign("my-signing-key", b"Hello, World!", None).await?;
// Verify signature
let valid = crypto_tee.verify("my-signing-key", b"Hello, World!", &signature, None).await?;
println!("Signature valid: {}", valid);
Ok(())
}- API Documentation - Complete API reference
- API Guide - Comprehensive usage guide
- Examples - Sample code for common use cases
- Architecture - System design and internals
- Contributing - How to contribute
- Development - Development setup and guidelines
| Platform | Vendor | Hardware Security | Authentication | Status |
|---|---|---|---|---|
| macOS/iOS | Apple | Secure Enclave | Touch/Face ID | β Complete |
| Samsung Android | Knox | TrustZone + Knox Vault | Fingerprint + Knox | β Complete |
| Qualcomm Android | QSEE | TrustZone | Fingerprint | π§ In Progress |
| Android 6+ | AOSP | Keystore/StrongBox | Fingerprint | β Complete |
| Linux | OP-TEE/SGX | Hardware TEE | PIN/Biometric | β Complete |
| Windows | Software | None | PIN | β Complete |
| Web/WASM | Software | None | None | π§ Beta |
βββββββββββββββββββββββββββββββββββββββββββ
β Application Layer β
βββββββββββββββββββββββββββββββββββββββββββ€
β RFC 9421 HTTP Signatures (L4) β
βββββββββββββββββββββββββββββββββββββββββββ€
β CryptoTEE Core API (L3) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Platform Abstraction (L2) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Vendor TEE Layer (L1) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Hardware TEE (Knox/SE/QSEE/etc.) β
βββββββββββββββββββββββββββββββββββββββββββ
// Generate different key types
let signing_key = crypto_tee.generate_key(
"signing-key",
KeyOptions {
algorithm: Algorithm::Ed25519,
usage: KeyUsage::SIGN_VERIFY,
..Default::default()
},
).await?;
let encryption_key = crypto_tee.generate_key(
"encryption-key",
KeyOptions {
algorithm: Algorithm::Aes256,
usage: KeyUsage::ENCRYPT_DECRYPT,
..Default::default()
},
).await?;// Create key requiring biometric authentication
let secure_key = crypto_tee.generate_key(
"secure-key",
KeyOptions {
algorithm: Algorithm::EcdsaP256,
require_auth: true, // Requires Touch/Face ID
..Default::default()
},
).await?;
// This will prompt for biometric authentication
let signature = crypto_tee.sign("secure-key", data, None).await?;use crypto_tee::vendors::samsung::KnoxParams;
// Create key in Knox Vault for maximum security
let knox_key = crypto_tee.generate_key_with_vendor_params(
"knox-key",
KeyOptions {
algorithm: Algorithm::EcdsaP256,
hardware_backed: true,
..Default::default()
},
VendorParams::Samsung(KnoxParams {
use_knox_vault: true,
require_user_auth: true,
use_trustzone: true,
enable_attestation: true,
..Default::default()
}),
).await?;use crypto_tee_rfc9421::HttpSignatureBuilder;
// Sign HTTP requests
let builder = HttpSignatureBuilder::new(crypto_tee, "signing-key".to_string());
let signed_request = builder.sign_request(request).await?;See the examples directory for more:
- Basic key management
- Signing and verification
- HTTP signatures
- Apple Secure Enclave
- Samsung Knox Vault
- Multi-platform usage
- Plugin development
- Authentication flows
- Hardware-backed keys - Private keys never leave the secure hardware (Apple Secure Enclave, Samsung Knox Vault)
- Biometric authentication - Protect operations with Touch/Face ID, fingerprint, or Knox authentication
- Hardware attestation - Cryptographic proof that keys are hardware-protected with certificate chains
- Constant-time operations - Protection against timing side-channel attacks
- Automatic zeroization - Sensitive data is cleared from memory after use
- Non-extractable keys - Prevent key export for maximum security
- Knox Vault integration - Samsung's highest security tier with hardware isolation
- TrustZone support - ARM TrustZone integration on Android devices
- Platform detection - Automatic selection of best available security features
Typical operation times with hardware-backed keys:
| Operation | Ed25519 | ECDSA P-256 | RSA-2048 |
|---|---|---|---|
| Generate | 10-20ms | 15-30ms | 100-200ms |
| Sign | 1-5ms | 5-15ms | 20-100ms |
| Verify | 1-3ms | 3-10ms | 5-20ms |
[dependencies]
crypto-tee = "0.1"
# Optional features
crypto-tee = { version = "0.1", features = ["plugins"] }
# Platform-specific features
[target.'cfg(target_os = "macos")'.dependencies]
crypto-tee = { version = "0.1", features = ["apple"] }
[target.'cfg(target_os = "android")'.dependencies]
crypto-tee = { version = "0.1", features = ["samsung", "qualcomm"] }plugins- Enable plugin systemsoftware-fallback- Enable software implementationapple- Apple Secure Enclave supportsamsung- Samsung Knox supportqualcomm- Qualcomm QSEE supportsimulator- TEE simulator for development
# Clone the repository
git clone https://github.com/procatstler/crypto-tee-core.git
cd crypto-tee-core
# Build all features
cargo build --all-features
# Run tests
cargo test --all-features
# Run benchmarks
cargo bench
# Build documentation
cargo doc --all-features --openWe welcome contributions! Please see our Contributing Guide for details.
- Install Rust 1.70+
- Clone the repository
- Run
cargo testto verify setup - See DEVELOPMENT.md for detailed instructions
For security issues, please see our Security Policy. Do not report security vulnerabilities through public GitHub issues.
Licensed under the Apache License, Version 2.0. See LICENSE for details.
- Built with ring for cryptographic primitives
- Inspired by Web Crypto API design
- RFC 9421 implementation based on HTTP Message Signatures
- π§ Email: security@example.com
- π¬ Discord: Join our server
- π Issues: GitHub Issues
- π Docs: docs.rs/crypto-tee