TL;DR
This paper introduces a novel method for formatted encryption that moves beyond regular languages to support context-free grammars (CFGs). This allows for more expressive and practical data formats, like programming languages or network protocols, to be securely encrypted using format-preserving and format-transforming encryption (FPE/FTE) schemes. The key innovation is a "structural ranking" algorithm that efficiently maps CFG-based data structures to integers, enabling practical FPE/FTE implementations for these richer formats.
What Problem Does This Paper Address?
Formatted encryption, including FPE and FTE, is crucial for applications requiring data to maintain specific structures even after encryption. Existing methods primarily rely on regular expressions to define these formats. While powerful, regular expressions are insufficient for describing many real-world data structures like programming languages, file formats, or complex network protocols, which are better represented by context-free grammars (CFGs). The challenge has been the lack of efficient algorithms to "rank" (map to integers) and "unrank" (map from integers) strings conforming to CFGs, a fundamental requirement for most formatted encryption schemes. Existing CFG-based ranking methods are either too slow, only work for unambiguous grammars, or lack corresponding unranking capabilities, making them impractical for real-world use. Furthermore, practical grammars often use a two-level approach (lexical tokens defined by regexes and syntax defined by CFGs), which existing methods struggle to handle efficiently.
Methods
The paper's core contribution is a new algorithm for relaxed ranking from context-free grammars (CFGs). This approach works in two stages:
- Parse Tree Generation: The first step involves mapping strings from the language to their corresponding parse trees. The authors introduce the concept of minimal parse trees to ensure finiteness and manage complexity.
- Structural Ranking of Parse Trees: The second, and novel, step is a structural ranking algorithm applied to these parse trees. This algorithm allows for distinct ranking strategies for different grammar symbols and, crucially, for lexical tokens. This "type-based customization" is key to handling the practical two-level grammar specifications (syntax + lexical rules) efficiently.
The authors also introduce a relaxed ranking scheme, which maps strings to integers in a larger range than strictly necessary, allowing for more flexibility and efficiency. They provide algorithms for both ranking and unranking parse trees and demonstrate how this can be integrated into existing FPE/FTE frameworks. Additionally, they develop a C++ library and a code generation tool to facilitate the implementation of these ranking schemes, allowing users to specify grammars using familiar YACC/LEX-like syntax.
Datasets
Not discussed in the paper. The paper focuses on developing algorithms and evaluating them on grammars representing common data structures.
Key Insights and Ideas
- CFGs are Necessary for Richer Formats: The paper strongly argues that regular expressions are insufficient for many practical data formats, and CFGs are essential for expressive and secure formatted encryption.
- Parse Trees as Intermediate Representation: Using parse trees as an intermediate step for ranking CFG-based languages is a powerful abstraction that simplifies the ranking problem.
- Structural Ranking for Efficiency: The novel "structural ranking" approach, which allows customization based on grammar symbols and tokens, is critical for achieving practical performance, especially when dealing with lexical tokens defined by regular expressions.
- Relaxed Ranking's Practicality: Relaxed ranking, while theoretically less strict, proves to be a practical and efficient solution for formatted encryption, with ambiguity factors being low in real-world scenarios.
- Tooling is Crucial: The development of a user-friendly tool that converts YACC/LEX-like specifications into ranking code significantly lowers the barrier to entry for using these advanced techniques.
Key Results
- Efficient CFG Ranking: The proposed relaxed ranking algorithm for CFGs is demonstrated to be efficient, with ranking and unranking operations completing in under one second for complex languages like C99 with slices up to 4,000 bytes.
- Practical Ambiguity Handling: Despite the theoretical challenges of grammar ambiguity, the experiments show that in practice, ambiguity does not significantly hinder performance. Even with highly ambiguous grammars, the number of "outsiders" (strings that don't map back correctly) was negligible, leading to low ambiguity factors.
- Tooling Success: The code generation tool significantly simplifies the process of creating ranking code, reducing specification time from hours to minutes for complex grammars.
- Performance: Memoization for ranking tables takes time and space, but once computed, ranking and unranking are very fast. The size of the intermediate set (used in relaxed ranking) grows exponentially with the slice size, but the ranking/unranking operations themselves remain efficient.
Limitations and Future Work
- Grammar Ambiguity: While experiments suggest ambiguity is not a practical issue, the paper acknowledges that it's impossible to decide if a grammar is ambiguous. The relaxed ranking approach is designed to handle this, but the ambiguity factor can still influence performance.
- Non-Context-Free Formats: The paper touches upon handling formats that are not strictly context-free (e.g., those with counters or checksums) by defining a "cfg-parseable" language concept. However, this requires user-provided
mapandgenfunctions, and the current tool does not fully automate this. - Comments and Whitespace: The current tool's strategy is to ignore comments and whitespace, which might not be suitable for all formats. While it can insert canonical whitespace, the original comments are lost. Automating the inclusion of comments and whitespace in the grammar transformation is suggested as future work.
- Tool Automation: While the tool handles lexical clashes automatically, more complex transformations for handling comments and whitespace could be further automated.
Summary updated