Skip to content

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:

const config = {
  scheme: "BFV",
  securityLevel: 128,
  polyModulusDegree: 4096,
};

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

  1. Key Management

  2. Secure key generation and storage

  3. Automatic key rotation support
  4. Proper cleanup of sensitive materials

  5. Parameter Selection

  6. Choose appropriate polynomial modulus degree based on security requirements

  7. Balance between security level and performance
  8. Consider noise budget for operation depth

  9. Error Handling

  10. Comprehensive validation of inputs
  11. Secure error messages
  12. Proper cleanup on failures

Best Practices

  1. Operation Planning

  2. Plan computation depth to minimize noise accumulation

  3. Use batching for multiple operations
  4. Consider matrix dimensions for optimal performance

  5. Security Level Selection

  6. Use at least 128-bit security for production

  7. Consider 192 or 256-bit for highly sensitive data
  8. Balance security with performance requirements

  9. Resource Management

  10. Properly initialize and cleanup FHE resources
  11. Monitor memory usage for large matrices
  12. Use batching for better resource utilization

Future Enhancements

  1. Additional Features

  2. Support for more advanced matrix decompositions

  3. Integration with machine learning operations
  4. Optimization for specific hardware accelerators

  5. Performance Improvements

  6. GPU acceleration support

  7. Advanced batching strategies
  8. Parallel processing optimizations

  9. Security Enhancements

  10. Additional key management features
  11. Enhanced audit logging
  12. Advanced access control integration