Writing code is hard; proving it correct is even harder. As the scale of verified software projects reaches new heights, the problem of efficiently verifying large amounts of software becomes more and more salient. Nowhere is this issue more evident than in the context of verified cryptographic libraries. To achieve feature-parity and be competitive with unverified cryptographic libraries, a very large number of algorithms and APIs need to be verified. However, the task is oftentimes repetitive, and factoring out commonality between algorithms is fraught with difficulties, requiring until now a significant amount of manual effort. This paper shows how a judicious combination of known functional programming techniques leads to an order-of-magnitude improvement in the amount of verified code produced by the popular HACL* cryptographic library, without compromising performance. We review three techniques that build upon each other, in order of increasing sophistication. First, we use dependent types to crisply capture the specification and state machine of a block algorithm, a cryptographic notion that was until now only informally and imprecisely specified. Next, we rely on partial evaluation to author a higher-order, stateful functor that transforms any unsafe block API into a safe counterpart. Finally, we rely on elaborator reflection to automate the very process of authoring a functor, using a code-rewriting tactic. This culminates in a style akin to templatized C++ code, but relying on a userland tactic and partial evaluation, rather than built-in compiler support.
翻译:写法是硬的; 证明它是正确的。 随着经过核查的软件项目的规模达到新的高度, 有效核查大量软件的问题变得越来越突出。 这个问题在经过核查的加密图书馆中最为明显。 为了实现特性平等, 并且与未经核查的加密图书馆竞争, 需要核查大量的算法和API。 但是, 这项任务往往重复重复, 并且将各种算法的共性因素考虑在内, 直到现在还需要大量手工工作。 本文显示, 已知的功能性编程技术的明智结合如何导致在经过核查的加密图书馆所制作的代码数量方面出现惊人的改进。 为了实现特征平等, 并与未经核查的加密图书馆竞争, 我们审查三个相互加强的技术, 以便提高精密程度。 首先, 我们使用依赖的类型来精确地捕捉成块算法的规格和状态机器, 一种加密的概念, 直到现在才需要大量手工努力。 其次, 我们依靠部分评价来撰写一种更高级的, 州级的调调调制的战术, 一种安全性对等式的编程, 一种我们使用一种安全性化的编程, 的编程, 一种安全的编程的编程, 一种我们使用一个安全的编程的编程的编程。