Application of type-safe state machines in OCaml for authenticated key exchange

Authors

DOI:

https://doi.org/10.18372/2073-4751.87.21684

Keywords:

OCaml, generalized algebraic data types (GADT), typed state machine, TLS 1.3, Noise protocol, authenticated key exchange, TLS termination, load balancing, unikernels, MirageOS

Abstract

A significant share of vulnerabilities in secure communication protocols, including those in the TLS termination nodes of cloud infrastructure load balancers, stems from handshake state management errors. A method is proposed for constructing TLS 1.3 and Noise state machines in OCaml in which the transition relation is encoded as a generalized algebraic data type (GADT) and mandatory cryptographic checks are enforced by proof tokens, so message ordering violations and omitted checks are detected by the compiler. Experiments show that out of 49 TLS 1.3 state–message pairs the compiler accepts exactly 7, matching RFC 8446, while the overhead does not exceed 0.05 % of handshake time and does not reduce the throughput of TLS termination nodes. The limitations of the method and a plan for integration into the ocaml-tls library for MirageOS unikernels are outlined.

References

1. B. Beurdouche et al., "A Messy State of the Union: Taming the Composite State Machines of TLS," in Proc. IEEE Symp. Security and Privacy (S&P), San Jose, CA, USA, 2015, pp. 535–552, doi: 10.1109/SP.2015.39.

2. E. Rescorla, "The Transport Layer Security (TLS) Protocol Version 1.3," IETF RFC 8446, Aug. 2018, doi: 10.17487/RFC8446.

3. T. Perrin, "The Noise Protocol Framework," Revision 34, 2018. [Online]. Available: https://noiseprotocol.org/noise.html

4. D. Stebila, S. Fluhrer, and S. Gueron, "Hybrid key exchange in TLS 1.3," IETF Internet-Draft draft-ietf-tls-hybrid-design, 2025.

5. H. Mehnert and D. Kaloper-Meršinjak, "ocaml-tls: TLS in pure OCaml," 2026. [Online]. Available: https://github.com/mirleft/ocaml-tls

6. Y. Kotukh, A. Honcharuk, M. Korobchynskyi, I. Kiris, M. Rudenko, and V. Voitko, "Type Safe OCaml Bindings for the Open Quantum Safe Post-Quantum Cryptography Library," in Proc. IEEE Int. Conf., 2026, accepted for publication.

7. Y. Kotukh, G. Khalimov, I. Dzhura, and H. Hivrenko, "Application of the LINE encryption scheme in the key encapsulation mechanism for the authentication protocol in 5G networks," Radiotekhnika, no. 219, pp. 36–45, 2024, doi: 10.30837/rt.2024.4.219.04.

8. K. Bhargavan, B. Blanchet, and N. Kobeissi, "Verified Models and Reference Implementations for the TLS 1.3 Standard Candidate," in Proc. IEEE Symp. Security and Privacy (S&P), 2017, pp. 483–502, doi: 10.1109/SP.2017.26.

9. A. Delignat-Lavaud et al., "Implementing and Proving the TLS 1.3 Record Layer," in Proc. IEEE Symp. Security and Privacy (S&P), 2017, pp. 463–482, doi: 10.1109/SP.2017.58.

10. J. Protzenko et al., "EverCrypt: A Fast, Verified, Cross-Platform Cryptographic Provider," in Proc. IEEE Symp. Security and Privacy (S&P), 2020, pp. 983–1002, doi: 10.1109/SP40000.2020.00114.

11. Cryspen, "libcrux: Formally verified cryptography in Rust," 2025. [Online]. Available: https://github.com/cryspen/libcrux

12. N. Kobeissi, G. Nicolas, and K. Bhargavan, "Noise Explorer: Fully Automated Modeling and Verification for Arbitrary Noise Protocols," in Proc. IEEE European Symp. Security and Privacy (EuroS&P), 2019, pp. 356–370, doi: 10.1109/EuroSP.2019.00034.

13. S. J. Gay and M. Hole, "Subtyping for session types in the pi calculus," Acta Informatica, vol. 42, no. 2–3, pp. 191–225, 2005, doi: 10.1007/s00236-005-0177-z.

14. L. Padovani, "A simple library implementation of binary sessions," Journal of Functional Programming, vol. 27, e4, 2017, doi: 10.1017/S0956796816000289.

15. K. Imai, R. Neykova, N. Yoshida, and K. Yuen, "Multiparty Session Programming with Global Protocol Combinators," in Proc. 34th European Conf. Object-Oriented Programming (ECOOP), LIPIcs vol. 166, 2020, pp. 9:1–9:30, doi: 10.4230/LIPIcs.ECOOP.2020.9.

16. A. Lorenzen, L. White, S. Dolan, R. A. Eisenberg, and S. Lindley, "Oxidizing OCaml with Modal Memory Management," Proc. ACM Program. Lang., vol. 8, no. ICFP, art. 253, 2024, doi: 10.1145/3674642.

17. J. Garrigue and D. Rémy, "Ambivalent Types for Principal Type Inference with GADTs," in Proc. Asian Symp. Programming Languages and Systems (APLAS), LNCS vol. 8301, 2013, pp. 257–272, doi: 10.1007/978-3-319-03542-0_19.

18. K. C. Sivaramakrishnan, S. Dolan, L. White, S. Jaffer, T. Kelly, A. Sahoo, S. Parimala, A. Dhiman, and A. Madhavapeddy, "Retrofitting Parallelism onto OCaml," Proc. ACM Program. Lang., vol. 4, no. ICFP, art. 113, 2020, doi: 10.1145/3408995.

19. K. C. Sivaramakrishnan, S. Dolan, L. White, T. Kelly, S. Jaffer, and A. Madhavapeddy, "Retrofitting Effect Handlers onto OCaml," in Proc. 42nd ACM SIGPLAN Conf. Programming Language Design and Implementation (PLDI), 2021, pp. 206–221, doi: 10.1145/3453483.3454039.

20. MirageOS Project, "mirage-crypto: Cryptographic primitives for OCaml – CHANGES," 2026. [Online]. Available: https://github.com/mirage/mirage-crypto/blob/main/CHANGES.md

21. O. Reparaz, J. Balasch, and I. Verbauwhede, "Dude, is my code constant time?" in Proc. Design, Automation & Test in Europe Conf. (DATE), 2017, pp. 1697–1702, doi: 10.23919/DATE.2017.7927267.

Published

2026-11-10

How to Cite

Kotukh, Y., & Shklyar, O. (2026). Application of type-safe state machines in OCaml for authenticated key exchange. Problems of Informatization and Control, 3(87), 65–74. https://doi.org/10.18372/2073-4751.87.21684

Issue

Section

Статті