Secure and efficient general matrix multiplication on cloud using homomorphic encryption

Yang Gao, Gang Quan, Soamar Homsi, Wujie Wen, Liqiang Wang

Abstract

Homomorphic Encryption (HE) provides a robust framework for privacy-preserving cloud computing, allowing servers to process encrypted data without accessing the underlying plaintext. However, the computational overhead of HE, particularly for fundamental operations like Matrix Multiplication (MM), remains a significant barrier to practical adoption. This paper introduces HEGMM and HEGMM-En, two novel algorithms designed to optimize matrix multiplication within HE schemes. By leveraging Single Instruction Multiple Data (SIMD) operations and innovative matrix transformation operators, these algorithms achieve an average speedup of 4.13x and up to 154x compared to existing state-of-the-art methods. Our approach demonstrates that through efficient data layout and the strategic duplication of ciphertexts, the "multiplication tax" of HE can be substantially mitigated.

1. Introduction

As cloud computing becomes the standard for large-scale data processing, sectors handling sensitive information—such as healthcare and government—face a critical dilemma: the trade-off between computational scalability and data privacy. Homomorphic Encryption (HE) is often cited as the definitive solution to this problem, as it enables mathematical operations to be performed directly on encrypted ciphertexts. The result, once decrypted by the data owner, is identical to the result of operations performed on plaintext.

Despite its promise, HE is notoriously slow. Matrix Multiplication, the core component of modern artificial intelligence and statistical analysis, represents a massive computational bottleneck in the encrypted domain. Existing HE-MM methods often suffer from inefficiencies, such as failing to fully utilize the "slots" available in modern HE ciphertexts or struggling to handle non-square (rectangular) matrices efficiently. This paper addresses these limitations by proposing a general matrix multiplication framework that maximizes SIMD utilization and minimizes expensive homomorphic multiplications.

2. Methodology

2.1 Element-Wise Computation and Operators

Unlike traditional row-column dot product approaches, the proposed algorithms utilize an element-wise computation strategy. To facilitate this, the authors introduce four specific matrix transformation operators:

  • $\sigma$ and $\tau$: These operators perform row and column rotations to align matrix elements for initial processing.
  • $\epsilon$ and $\omega$: These are "shifting" operators that allow the algorithm to maintain flexibility when handling matrices of arbitrary, non-square shapes.

2.2 HEGMM and HEGMM-En

The research presents two distinct algorithmic variations:

  1. HEGMM (Basic): This version implements the element-wise method using SIMD operations. SIMD allows a single HE operation (such as addition or multiplication) to be applied simultaneously to thousands of data slots packed into a single ciphertext, significantly increasing throughput.
  2. HEGMM-En (Enhanced): This is the primary innovation of the paper. Recognizing that homomorphic multiplication (HE-Mult) is significantly more computationally expensive and noise-inducing than rotations or additions, HEGMM-En employs a data duplication strategy. If one matrix is smaller than the other, the algorithm duplicates the smaller matrix to fill the available ciphertext slots. This allows a single HE-Mult operation to compute multiple partial products at once, drastically reducing the total number of required multiplications.

2.3 Implementation Details

The algorithms were implemented using the Pyfhel library, utilizing the BFV (Brakerski-Fan-Vercauteren) encryption scheme. The data layout—whether the matrix is flattened in row-major or column-major order—was found to be a critical factor in performance, as it dictates the number of non-zero diagonals in the transformation matrices and, consequently, the total computational cost.

3. Experimental Evaluation

3.1 Setup

The performance of HEGMM and HEGMM-En was evaluated using 2,000 pairs of randomly generated matrices. The dimensions of these matrices ranged from 1 to 64. The upper limit of 64 was determined by the ciphertext slot capacity ($N=2^{12} = 4096$), which can accommodate a maximum square matrix of $64 \times 64$ in a single ciphertext.

3.2 Comparative Results

The proposed methods were compared against three major benchmarks: E2DM-S, E2DM-R, and Huang-MM.

  • Computational Speed: HEGMM-En achieved an average speedup of 4.13x over the E2DM benchmarks. The performance gains were most pronounced in scenarios involving highly rectangular matrices, where speedups reached as high as 132.42x (and up to 154x in specific edge cases).
  • Memory Efficiency: Both HEGMM and HEGMM-En demonstrated superior memory management, consuming less memory than E2DM and significantly less than the Huang-MM method.
  • Scalability: To handle matrices exceeding the $64 \times 64$ slot limit, the authors employed a "blocking" strategy. In tests with $100 \times 100$ matrices, the proposed method completed the multiplication in approximately 26 seconds, whereas competing methods required between 37 and 74 seconds.

4. Discussion and Limitations

While the results are promising, several constraints remain. The current implementation is bound by the ciphertext slot size; while blocking allows for larger matrices, it introduces additional architectural complexity. Furthermore, every homomorphic operation increases the "noise" within a ciphertext. While this paper focuses on efficiency, there is a finite limit to the number of multiplications possible before a costly "bootstrapping" operation is required to clear the noise.

5. Conclusion

HEGMM and HEGMM-En represent a significant step forward in making privacy-preserving cloud computing viable for data-heavy applications. By optimizing the data layout and prioritizing "cheap" rotations over "expensive" multiplications, the authors have significantly reduced the latency of encrypted matrix multiplication. Future research will focus on adapting these techniques for sparse matrix multiplication, which could unlock even greater efficiency for graph processing and large-scale neural networks.

Summary updated

BibTeX
@article{gao2024secure,
  author = {Yang Gao and Gang Quan and Soamar Homsi and Wujie Wen and Liqiang Wang},
  title = {{Secure and efficient general matrix multiplication on cloud using homomorphic encryption}},
  journal = {Journal of Supercomputing},
  year = {2024},
  doi = {10.1007/s11227-024-06428-8},
}
Figure