Fully Homomorphic Encryption (FHE)¶
AIDDDMAP implements Fully Homomorphic Encryption using Microsoft SEAL, enabling secure computation on encrypted data without decryption. This document outlines the configuration, usage, and capabilities of our FHE implementation.
Configuration¶
The FHE module can be configured with the following parameters:
interface FHEConfig {
scheme: "BFV" | "CKKS"; // Encryption scheme
securityLevel: 128 | 192 | 256; // Security level in bits
polyModulusDegree: number; // Polynomial modulus degree
plainModulus?: number; // Optional plain modulus for BFV scheme
}
Example configuration:
Core Operations¶
Basic Encryption and Decryption¶
const fheHandler = new FHEHandler(config);
const data = [1, 2, 3, 4, 5];
const encrypted = await fheHandler.encrypt(data);
const decrypted = await fheHandler.decrypt(encrypted);
Homomorphic Operations¶
Addition¶
const encrypted1 = await fheHandler.encrypt([1, 2, 3]);
const encrypted2 = await fheHandler.encrypt([4, 5, 6]);
const sum = await fheHandler.add(encrypted1, encrypted2);
// Result when decrypted: [5, 7, 9]
Multiplication¶
const encrypted1 = await fheHandler.encrypt([2, 3]);
const encrypted2 = await fheHandler.encrypt([4, 5]);
const product = await fheHandler.multiply(encrypted1, encrypted2);
// Result when decrypted: [8, 15]
Vector Rotation¶
const encrypted = await fheHandler.encrypt([1, 2, 3, 4]);
const rotated = await fheHandler.rotate(encrypted, 1);
// Result when decrypted: [4, 1, 2, 3]
Advanced Operations¶
Matrix Multiplication¶
The FHE implementation supports secure matrix multiplication:
const matrix1 = [
[1, 2],
[3, 4],
];
const matrix2 = [
[5, 6],
[7, 8],
];
// Encrypt matrices
const encryptedMatrix1 = await Promise.all(
matrix1.map((row) =>
Promise.all(row.map((val) => fheHandler.encrypt([val]))),
),
);
const encryptedMatrix2 = await Promise.all(
matrix2.map((row) =>
Promise.all(row.map((val) => fheHandler.encrypt([val]))),
),
);
// Perform multiplication
const result = await fheHandler.multiplyMatrix(
encryptedMatrix1,
encryptedMatrix2,
);
Floating-Point Operations (CKKS)¶
For operations involving floating-point numbers, use the CKKS scheme:
const ckksConfig = {
scheme: "CKKS",
securityLevel: 128,
polyModulusDegree: 8192,
};
const ckksHandler = new FHEHandler(ckksConfig);
const data = [1.5, 2.7, 3.14];
const encrypted = await ckksHandler.encrypt(data);
const decrypted = await ckksHandler.decrypt(encrypted);
Advanced Matrix Operations¶
Singular Value Decomposition (SVD)¶
The FHE implementation supports computing SVD on encrypted matrices, which is useful for dimensionality reduction, principal component analysis, and matrix approximation while maintaining data privacy:
// Example matrix
const matrix = [
[4, 0],
[3, -5],
];
// Encrypt matrix
const encryptedMatrix = await Promise.all(
matrix.map((row) => Promise.all(row.map((val) => fheHandler.encrypt([val])))),
);
// Perform SVD
const { U, S, V } = await fheHandler.performSVD(encryptedMatrix, {
rows: 2,
cols: 2,
});
// U contains left singular vectors
// S contains singular values
// V contains right singular vectors
Matrix Determinant and Inverse¶
For square matrices, you can compute determinants and inverses while maintaining encryption:
const encryptedDet = await fheHandler.performAdvancedMatrixOperation(
encryptedMatrix,
"determinant",
{ rows: 2, cols: 2 },
);
const encryptedInverse = await fheHandler.performAdvancedMatrixOperation(
encryptedMatrix,
"inverse",
{ rows: 2, cols: 2 },
);
Eigenvalue Approximation¶
The implementation includes methods for approximating eigenvalues of encrypted matrices:
const encryptedEigenvalues = await fheHandler.performAdvancedMatrixOperation(
encryptedMatrix,
"eigenvalue",
{ rows: 2, cols: 2 },
);
Performance Optimization¶
Batched Operations¶
For improved performance when dealing with multiple operations, use batched processing:
const encryptedBatch = await Promise.all(
dataArray.map((data) => fheHandler.encrypt(data)),
);
const results = await fheHandler.performBatchedOperation(encryptedBatch, "add");
Noise Management¶
The implementation includes automatic noise management to maintain precision during computations:
// Get current noise budget
const noiseBudget = await fheHandler.getNoiseBudget(encryptedData);
// Operations automatically manage noise through relinearization
const product = await fheHandler.multiply(encrypted1, encrypted2);
// Noise is reduced after multiplication
Security Considerations¶
-
Key Management
-
Secure key generation and storage
- Automatic key rotation support
-
Proper cleanup of sensitive materials
-
Parameter Selection
-
Choose appropriate polynomial modulus degree based on security requirements
- Balance between security level and performance
-
Consider noise budget for operation depth
-
Error Handling
- Comprehensive validation of inputs
- Secure error messages
- Proper cleanup on failures
Best Practices¶
-
Operation Planning
-
Plan computation depth to minimize noise accumulation
- Use batching for multiple operations
-
Consider matrix dimensions for optimal performance
-
Security Level Selection
-
Use at least 128-bit security for production
- Consider 192 or 256-bit for highly sensitive data
-
Balance security with performance requirements
-
Resource Management
- Properly initialize and cleanup FHE resources
- Monitor memory usage for large matrices
- Use batching for better resource utilization
Future Enhancements¶
-
Additional Features
-
Support for more advanced matrix decompositions
- Integration with machine learning operations
-
Optimization for specific hardware accelerators
-
Performance Improvements
-
GPU acceleration support
- Advanced batching strategies
-
Parallel processing optimizations
-
Security Enhancements
- Additional key management features
- Enhanced audit logging
- Advanced access control integration