Repurposing Neural Networks for Efficient Cryptographic Computation

Xin Jin, Shiqing Ma, Zhiqiang Lin

Modern data generation has outpaced traditional encryption speeds. While GPUs and TPUs provide the necessary raw compute power, developing high-performance cryptographic kernels is notoriously difficult, requiring specialized hardware knowledge and resulting in brittle, non-portable code. Presented at NDSS 2025, TENSORCRYPT addresses this by repurposing the highly optimized machinery of Deep Learning (DL) frameworks to accelerate encryption.

The TENSORCRYPT Framework

The core innovation of TENSORCRYPT is treating cryptographic algorithms not as sequential code, but as neural network models. The framework translates traditional cryptographic logic into a series of deterministic neural network layers. Unlike standard AI, these networks are non-statistical; they contain no learned weights. Instead, operations like XORs, S-box lookups, and bit-shifts are mapped directly to NN layers.

Side-by-side comparison of a cryptographic function (left) and its transformed neural network representation (right).

To ensure security, the authors employ two Domain-Specific Languages: CRYPT for traditional logic and NN for neural network layers. They provide a formal proof of trace and bisimulation equivalence, guaranteeing that the NN-based implementation produces outputs identical to the original algorithm for any given input. This symbolic translation preserves the security properties of the underlying cipher while enabling it to run on the DL stack. The authors lean on the fact that Recurrent Neural Networks (RNNs) are Turing-complete, meaning any computer program can, in theory, be represented as a neural network.

Optimization and Performance

By representing encryption as a computational graph, TENSORCRYPT can leverage advanced DL compilers like XLA and TVM. A key optimization is Operator Fusion, which combines numerous small bitwise operations into a single, efficient GPU kernel, significantly reducing scheduling overhead.

The process of operator fusion, where multiple small operations are combined into a single optimized kernel.

Evaluation across various hardware—from NVIDIA GTX 1080 Ti GPUs to Google TPUs and mobile devices—demonstrates substantial gains. TENSORCRYPT achieves up to a 5.44x speedup for ChaCha20 and 4.09x for AES compared to expert-written GPU implementations. Correctness was verified using standard NIST and RFC test vectors to ensure bit-for-bit accuracy. Furthermore, the "load-on-use" memory strategy improves encryption speeds by up to 92.5x by maximizing GPU memory efficiency. The framework also offers remarkable portability; the same model can be deployed on a cloud TPU or a mobile phone with minimal effort.

Security and Limitations

Because the weights are hardcoded and the logic is symbolically translated, the NN model does not introduce the "black box" uncertainty or adversarial vulnerabilities typically associated with AI. However, the current scope is limited to symmetric ciphers (AES, ChaCha20, Salsa20) that are highly parallelizable. Sequential modes like CBC or asymmetric algorithms (RSA, ECC) present more complex mapping challenges.

Additionally, while the logic is equivalent, running cryptography on GPUs/TPUs still leaves systems potentially vulnerable to hardware-level side-channel attacks, such as timing or power analysis.

Conclusion

TENSORCRYPT demonstrates that the massive investment in AI infrastructure can be repurposed for general-purpose high-performance computing tasks. This "write once, accelerate anywhere" approach offers a promising path toward portable, high-speed secure computation.

The TENSORCRYPT artifact is available at: https://github.com/OSUSecLab/TensorCrypt

Summary updated

BibTeX
@inproceedings{jin2025repurposing,
  author = {Xin Jin and Shiqing Ma and Zhiqiang Lin},
  title = {{Repurposing Neural Networks for Efficient Cryptographic Computation}},
  booktitle = {NDSS},
  year = {2025},
}
Figure