arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2606.07341cs.CR
收藏

大型语言模型在代码片段向后量子密码迁移中的实证评估

Empirical Evaluation of Large Language Models for Migration of Code Fragments to Post-Quantum Cryptography

Universidad Carlos III de Madrid(马德里卡洛斯三世大学)

Javier Pallarés de Bonrostro, Ana I. González-Tablas, María Isabel González Vasco

AI总结:

评估大型语言模型在将经典密码代码片段迁移至后量子密码中的能力,通过微调GPT-4.1-mini实现92.5%的功能正确率,优于零样本基线。

摘要:

向后量子密码(PQC)的过渡不仅需要替换易受攻击的密码原语,还需要重构周围的软件逻辑。虽然现有的PQC迁移框架提供了组织层面的指导,但实际的代码级修复仍然主要依赖人工且容易出错。本文评估了大型语言模型(LLM)是否可以被训练来协助将前量子密码代码片段迁移到后量子对应物,同时保持功能正确性。为此,我们引入了一个可重复的实验框架,该框架基于一个包含800个配对Python代码片段的合成数据集,涵盖六个密码家族和组合多原语案例。每个配对通过类别特定的功能测试进行验证,从而实现了数据集质量控制和模型生成迁移的客观评估。评估了四个模型:零样本设置下的GPT-4.1,以及微调版本的GPT-3.5-turbo、GPT-4.1-mini和CodeLlama-7B-Instruct。结果表明,领域特定的微调对于可靠的密码迁移至关重要。微调后的GPT-4.1-mini模型实现了最佳整体性能,平均静态相似度为0.9072,动态功能正确率为92.5%,显著优于零样本基线。对六个开源仓库的补充验证进一步表明,该方法可以在局部密码模块中产生有用的迁移,同时也揭示了在具有复杂依赖关系和跨模块交互的大型项目中的局限性。这些发现表明,微调后的LLM可以作为未来密码敏捷迁移管道中的实用组件,前提是它们与自动化验证和依赖感知验证相结合。

英文摘要:

The transition to post-quantum cryptography (PQC) requires not only replacing vulnerable cryptographic primitives, but also refactoring the surrounding software logic. While existing PQC migration frameworks provide organizational guidance, practical code-level remediation remains largely manual and error-prone. This paper evaluates whether large language models (LLMs) can be trained to assist in the migration of pre-quantum cryptographic code fragments to post-quantum counterparts while preserving functional correctness. To this end, we introduce a reproducible experimental framework built around a synthetic dataset of 800 paired Python code fragments covering six cryptographic families and combined multi-primitive cases. Each pair is validated through category-specific functional tests, enabling both dataset quality control and objective evaluation of model-generated migrations. Four models are assessed: GPT-4.1 in a zero-shot setting, and fine-tuned versions of GPT-3.5-turbo, GPT-4.1-mini, and CodeLlama-7B-Instruct. The results show that domain-specific fine-tuning is essential for reliable cryptographic migration. The fine-tuned GPT-4.1-mini model achieves the best overall performance, with a mean static similarity of 0.9072 and a dynamic functional correctness rate of 92.5%, substantially outperforming the zero-shot baseline. A complementary validation on six open-source repositories further shows that the approach can produce useful migrations in localized cryptographic modules, while also revealing limitations in larger projects with complex dependencies and cross-module interactions. These findings suggest that fine-tuned LLMs can serve as practical components in future crypto-agile migration pipelines, provided they are coupled with automated verification and dependency-aware validation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑