We present zero-cost, high-level F* functors and their compilation to low-level, efficient C code. Thanks to a combination of partial evaluation, fine-grained control of reduction, and tactic-driven C++ template-like metaprogramming, we provide the programmer with a toolkit that dramatically reduces the proof-to-code ratio, brings out the essence of algorithmic and implementation agility, and allows substantial code reuse while remaining at a very high-level of abstraction. None of our techniques require modifying the F* compiler. We describe a systematic process to develop functors, and illustrate it with the streaming functor, which wraps an error-prone, cryptographic block API by hiding internal buffering and state machine management to prevent C programmer mistakes. We apply this functor to 10 implementations from the HACLxN cryptographic library. We then write a tactic to automate the functor encoding, allowing the programmer to author multi-argument functors with a deeply nested call graph without any syntactic overhead. We apply this general tactic on 5 algorithms from HACL*, yielding over 30 specialized functor applications. We use as an example Curve25519, a complex algorithm whose final, specialized version we express as nested functor applications.
翻译:我们提出零成本、高水平F* 真菌及其编译为低水平、高效的C代码。我们通过部分评价、精细控制减排和策略驱动的C++模板式配方程式组合,向程序员提供了一套工具,大大降低了校对比对码率,提出了算法和执行的灵巧性,允许大量代码再利用,同时保持高度的抽象性。我们的技术都不要求修改F* 编译者。我们描述了开发真菌的系统过程,并用流式真菌来说明它,它包绕了一个易出错的、加密块的CPI, 隐藏了内部缓冲和州机管理来防止C程序错误。我们把这个真菌应用到HACLLN加密图书馆的10项执行中。然后我们写出一种策略,将真菌编码自动化,使程序员能够用深嵌的调制调真菌图来开发F* 。我们用这种普通的真菌配方程式来包植,我们把这种普通的真菌策略用于5种配方程式, 也就是HCLL* 的精制成30版的精制成一个专门的变方程式。我们用了它的精化模型,我们用了一个特殊的精化的精化的精制式的精制式变精制变精制式的精制式变方程式。