arXiv:2608.24498cs.CRAug 2026

Manuscript Offprint

arXiv:2608.24498

SeriCrypt: An LLM-Driven Context-Aware Serialization Framework for Cryptographic Protocols

Maosong Chen, Xi Chen, Mengcheng Ju, Dongliang Zhao, Chunxiang Gu

Maosong Chen †^{\dagger}, Xi Chen †⊗^{\dagger\otimes}, Mengcheng Ju †^{\dagger}, Dongliang Zhao †^{\dagger}, Chunxiang Gu †⊗^{\dagger\otimes}

†^{\dagger}Information Engineering University, Zhengzhou 450001, China

Email: chenmaosong1214@163.com, xycuckoo@tsinghua.org.cn, zhangph12138@163.com, xiao_xiang@163.com, gcx5209@126.com

Abstract—Constructing syntactically correct and cryptographically valid message sequences is essential for protocol state machine learning, conformance testing, and fuzzing. Unlike plaintext protocols, cryptographic protocols involve complex cross-message state dependencies and cryptographic computation constraints. Existing automated message construction approaches predominantly target text-based or plaintext protocols, lacking support for deep semantic dependencies and cryptographic operations, rendering cryptographic protocol message construction largely manual. We present SeriCrypt, an LLM-driven, context-aware serialization framework for cryptographic protocols. SeriCrypt uses a large language model (LLM) to extract protocol field constraints, contextual state dependencies, and cryptographic computation rules from unstructured protocol specifications, representing them as a unified structured intermediate representation. To formally characterize this representation, we design a domain-specific language for cryptographic protocols (CDSL) that explicitly captures semantic constraints and computational dependencies in protocol interactions. Building upon CDSL, we implement a protocol-agnostic execution engine that parses CDSL declarations and automates field value resolution, cryptographic primitive invocation, and byte-stream serialization. As case studies of SeriCrypt in protocol security testing, we employ the framework to construct violation messages targeting specification-defined security constraints and validate its application in protocol fuzzing scenarios, with evaluation on multiple mainstream implementations of TLS 1.2/1.3, IKEv1/v2, SSH, and TLCP. Results show SeriCrypt can generate valid message sequences accepted by real implementations and successfully complete handshakes across all evaluated scenarios. Security constraint testing revealed five specification violations, and fuzzing reached deeper protocol states with higher code coverage than mainstream fuzzers under the same time budget, demonstrating the framework's practical value for cryptographic protocol security testing.

Index Terms—cryptographic protocols, large language model, protocol serialization, domain-specific language, protocol security testing

I. INTRODUCTION

Cryptographic network protocols (e.g., TLS, IPsec, SSH) are the foundational infrastructure of modern network communication security, providing core functions such as confidentiality protection, identity authentication, and integrity verification. The security of these protocols depends not only on the completeness of the specification design but also on whether their implementations strictly adhere to the security constraints defined in the RFCs. Studies show that even when the specification itself is thoroughly verified, deviations at the implementation level can still lead to severe security vulnerabilities such as state machine bypass [1]–[4]. Therefore, security testing against protocol implementations is an indispensable means of ensuring communication security [5].

For encrypted protocols, constructing messages that conform to cryptographic specifications can effectively improve the efficiency of security testing methods such as fuzzing [6], state-machine learning [2], and conformance testing. This requires that messages not only satisfy precise byte-level encoding but also handle complex cryptographic computations within a complete session context, and that their values hold deep dependencies on the states of preceding interactions.

This strict requirement of cross-message state consistency and cryptographic correctness poses challenges for automating the construction of such messages. The knowledge required to construct such messages is described in natural language in protocol specifications (e.g., IETF RFCs and national standards). LLMs have natural language understanding capabilities and can automatically extract this protocol knowledge from the specification text, but two problems remain in their practical application: First, directly employing LLMs to generate binary messages or low-level handling code often fails to reliably meet the above constraints [7]. Second, although existing automation schemes have attempted to introduce formal protocol description languages to constrain LLMs in automatically extracting message layout, length, and nesting logic [8], [9], their research focus has primarily been on parsing and validating message syntactic structure, without covering cryptographic semantics such as key derivation, encryption encapsulation, and signature verification. As a result, even if developers can automatically obtain the syntactic skeleton and static attributes of messages, they still need to manually write substantial state maintenance and cryptographic computation code to construct valid messages that are actually accepted by the server.

To address this problem, this paper proposes SeriCrypt, a context-aware serialization framework for cryptographic protocols. The core idea of SeriCrypt is to decouple protocol structure description from cryptographic attribute computation. The LLM is only responsible for extracting a structured protocol intermediate representation—the Protocol Abstract Syntax Tree (PAST)—that conforms to the constraints of

CDSL. PAST organizes message formats in a hierarchical structure, and defines field lengths, cross-message references, key derivation, and encryption/decryption processes through attribute rules. Then the execution engine parses these attribute rules, calls underlying cryptographic primitives, and completes the evaluation and serialization. This design automates the construction of cryptographic protocol messages, and further allows testers to modify message structures at the PAST level to generate test sequences that conform to cryptographic specifications, thereby supporting security testing of protocol implementations.

We have implemented SeriCrypt and evaluated it on mainstream open-source implementations including OpenSSL, TLSE, strongSwan, Libreswan, OpenSSH, and GmSSL. The experiments cover six cryptographic protocols: TLS 1.2/1.3, IKEv1/v2, SSH, and TLCP. The results show that SeriCrypt can automatically construct acceptable legitimate message sequences and successfully complete full handshakes. In addition, we applied SeriCrypt to protocol security testing scenarios and discovered five security violations.

The contributions of this paper include:

• Context-aware protocol representation. We designed a domain-specific language for cryptographic protocols, CDSL, for uniformly describing message structures, field attributes, cross-message context references, and cryptographic computation rules such as key derivation, encryption, and authentication.

• Specification-driven automatic extraction process. We propose an LLM-based specification extraction chain-of-thought that extracts the Protocol Abstract Syntax Tree based on the LLM’s existing protocol knowledge, reducing the cost of manually organizing protocol messages and cryptographic dependency rules.

• Protocol-independent general execution engine. We implemented a modular execution engine for CDSL attributes that completes field evaluation, cryptographic operation execution, and message serialization, so that protocol differences are mainly reflected in the CDSL description layer while the underlying execution mechanism can be reused across protocols.

• Experimental validation and security testing application. Through end-to-end evaluation of six mainstream implementations across six cryptographic protocols, we verified the interoperability of the messages generated by SeriCrypt for cryptographic protocols. Meanwhile, experiments demonstrate its supporting capability in protocol security testing scenarios, with five security violations discovered.

References (33)