TFHE-Coder: Evaluating LLM Agents for secure Fully Homomorphic Encryption Code Generation
Abstract
Fully Homomorphic Encryption over the Torus (TFHE) is a cornerstone of confidential computing, yet its adoption is severely limited by a steep learning curve and the need for specialized cryptographic expertise. To bridge this skills gap, we explore if Large Language Models (LLMs) Agents can translate natural language specifications into secure TFHE code. We introduce a novel, three-phase agentic framework designed to overcome the primary failure points in this process. First, in the Instruction Phase, we automatically refine user queries into a structured Formal Prompt. Second, during the Generation Phase, a specialized Retrieval-Augmented Generation (RAG) tool provides the agent with accurate API knowledge from TFHE documentation. Finally, in the Feedback Phase, an automated Security Check module analyzes the output for cryptographic flaws and provides targeted feedback for iterative correction. We comprehensively evaluate our framework by testing four LLMs across five programming tasks of increasing difficulty. Our results demonstrate that baseline framework often produce functional but insecure code, while our framework is uniquely superior, consistently generating solutions that are simultaneously compilable, functionally correct, and secure. This work establishes a robust methodology and benchmark for TFHE code generation, demonstrating a viable path toward democratizing secure computation.