Code generation A secure C subset for automated Rust conversion

From | Translated by AI 2 min Reading Time

Researchers at the Computer Science Center INRIA in Paris have developed a subset of the C programming language that can be directly compiled into Rust with minimal effort. The C subset is intended to assist in the automatic translation of libraries written in C into Rust to achieve more secure code that is less vulnerable to hacking through memory issues.

The popularity of the Rust language continues to grow, yet many critical codebases are still written in C. Researchers at the INRIA Computer Science Center in Paris have now published their findings on an approach for converting entire C libraries to Rust with minimal effort.(Image: AI-generated / DALL-E)
The popularity of the Rust language continues to grow, yet many critical codebases are still written in C. Researchers at the INRIA Computer Science Center in Paris have now published their findings on an approach for converting entire C libraries to Rust with minimal effort.
(Image: AI-generated / DALL-E)

"Many critical codebases are still written in C and realistically cannot be manually rewritten. The automatic translation from C to Rust is therefore an attractive approach," says Aymeric Fromherz, a researcher at INRIA in Paris. Rust's paradigm aims at generating memory-safe code, which is not always guaranteed in C. However, C has been firmly established in the programming world for decades and has numerous libraries that would have to be completely redeveloped for Rust. An easy method of converting such libraries to Rust, which trivially ensures memory safety by following Rust's paradigm, would be very attractive as it saves laborious redevelopment efforts.

The INRIA team, with the approach pursued by the researchers, successfully ported the C version of the cryptographic library HACL* to Rust for the first time. The result is an 80,000-line verified cryptographic library, written in pure Rust, that implements all modern algorithms.

"Our work includes several original contributions: a type-driven translation from (a subset of) C to safe Rust; a novel static analysis based on 'split trees' that enables expressing C pointer arithmetic with Rust's slices and splitting operations; an analysis that precisely determines which borrows need to be mutable; and a compilation strategy for the struct types of C that is compatible with the distinction between non-owning and owning assignments in Rust," he said.

Along with the cryptographic library HACL*, this approach was used with binary parsers and serializers from EverParse and demonstrates that the subset of C is sufficient to translate both applications into secure Rust. For the few areas that violate Rust's aliasing discipline, automated, surgical rewrites are sufficient, he says.

The INRIA team has published their findings in a preprint study on the open-access platform arxiv.org of Cornell University, titled "Compiling C to Safe Rust, Formalized." The paper is available as a PDF on the linked page under a Creative Commons license (CC BY-NC-SA 4.0). (sg)

Subscribe to the newsletter now

Don't Miss out on Our Best Content

By clicking on „Subscribe to Newsletter“ I agree to the processing and use of my data according to the consent form (please expand for details) and accept the Terms of Use. For more information, please see our Privacy Policy. The consent declaration relates, among other things, to the sending of editorial newsletters by email and to data matching for marketing purposes with selected advertising partners (e.g., LinkedIn, Google, Meta)

Unfold for details of your consent