NssMPClib - A General-Purpose Secure Multi-Party Computation Library Based on PyTorch
Introduction
NssMPClib is a secure multi-party computation (MPC) library designed specifically for machine learning, offering
familiar PyTorch-style APIs that make privacy-preserving machine learning development as straightforward as regular
PyTorch programming.
It implements diverse privacy-preserving computation protocols based on both Arithmetic Secret Sharing and Function
Secret Sharing.
Key Features
PyTorch Integration: Leverages PyTorch tensor operations for ease of use
Torch-like APIs: Familiar APIs for seamless transition from standard PyTorch to secure computation
Multiple Security Models: Supports both Semi-Honest and Honest-Majority security assumptions
Flexible Party Configurations: 2-party and 3-party computation setups
Multiple Secret Sharing Schemes:
Additive Secret Sharing (2-party)
Replicated Secret Sharing (3-party)
Function Secret Sharing (FSS) implementations with multiple variants:
Privacy-Preserving Neural Network Inference: Support for secure model evaluation
Ring-based Computation: All operations performed on finite rings for cryptographic security
System Requirements
OS: Linux (required for proper compilation)
Python: 3.10 or higher (recommended: 3.12)
PyTorch: >=2.3.0 (recommended: 2.7.1)
Additional: C++ compiler (gcc/g++), CUDA toolkit (for GPU support)
Configure the library in nssmpc/config/configs.json:
{
"BIT_LEN": 32, // Ring size: 32 or 64 bits
"DEVICE": "cuda", // Compute device: "cpu" or "cuda"
"DTYPE": "float", // Data type: "float" or "int"
"SCALE_BIT": 8, // Fixed-point scaling bits
"DEBUG_LEVEL": 2 // Debug level: 0-Secure, 1-Testing, 2-Development
}
DEBUG_LEVEL Details:
0 (Secure Mode): Highest security. All pre-generated keys are destroyed after use, strictly following the One-Time Pad principle.
1 (Testing Mode): Performance-optimized. Inputs with the same dimensions reuse the same set of keys, facilitating performance testing and batch operations.
2 (Development Mode): Convenient for development. Uses a single globally-shared pre-generated key for all operations. ONLY for non-sensitive development environments.
Usage Scenarios:
DEBUG_LEVEL: 0 - Production environments with real sensitive data
DEBUG_LEVEL: 1 - Performance testing environments, evaluating performance across different input sizes
DEBUG_LEVEL: 2 - Protocol development environments, quickly verifying functional correctness
NssMPClib - A General-Purpose Secure Multi-Party Computation Library Based on PyTorch
Introduction
NssMPClib is a secure multi-party computation (MPC) library designed specifically for machine learning, offering familiar PyTorch-style APIs that make privacy-preserving machine learning development as straightforward as regular PyTorch programming.
It implements diverse privacy-preserving computation protocols based on both Arithmetic Secret Sharing and Function Secret Sharing.
Key Features
System Requirements
Installation
Step 1: Clone and Install
Step 2: Generate Cryptographic Parameters
Generate essential precomputed parameters for MPC operations:
Note: Parameters are saved to
~/NssMPClib/data/(32-bit indata/32/, 64-bit indata/64/).Quick Start: 2-Party Computation Example
Party 0 -
party_0.py:Party 1 -
party_1.py:Execution:
Running Built-in Examples
1. Arithmetic Secret Sharing (2-Party)
2. Neural Network Inference (2-Party)
3. Replicated Secret Sharing (3-Party)
Configuration
Configure the library in
nssmpc/config/configs.json:DEBUG_LEVEL Details:
Usage Scenarios:
DEBUG_LEVEL: 0- Production environments with real sensitive dataDEBUG_LEVEL: 1- Performance testing environments, evaluating performance across different input sizesDEBUG_LEVEL: 2- Protocol development environments, quickly verifying functional correctnessProject Structure
Precomputed Cryptographic Parameters
The library uses pre-generated parameters for efficiency. Key types include:
and so on…
Tutorials
Detailed tutorials are available in the
tutorials/directory:Best Practices
with PartyRuntime(party):Troubleshooting
Common Issues:
“Parameters not found” Error:
Port Already in Use: Change base port in
configs.jsonor kill existing processes.CUDA Errors: Set
DEVICE: "cpu"in config or check CUDA installation.Contributing
We welcome contributions! Please:
Citation
If you use NssMPClib in your research, please cite:
License
NssMPClib is released under the MIT License. See the LICENSE file for details.
Contact
Acknowledgements
Maintained by the Network and System Security (NSS) Laboratory at Xidian University.