Debian Codegraph @

crt/s2n/tests/saw/README.md

raw symbols SCIP
1 # SAW tests for s2n
2
3 This repository contains specifications of the various parts of the HMAC
4 algorithm used in TLS along with SAW scripts to prove the s2n implementation of
5 this algorithm equivalent to the spec.
6
7
8 ## The tests
9
10 Currently this directory houses a test that compares the s2n
11 implementation of HMAC with a cryptol spec of the same. There are 3
12 files that take part in this test.
13
14 1. bitcode/all_llvm.bc
15 2. spec/HMAC.cry
16 3. spec/HMAC.saw
17
18 all_llvm.bc contains linked llvm bitcode definitions for the entirety
19 of s2n/crypto. This bitcode is not currently linked with code from the
20 other directories in s2n, because so far, those directories have not
21 contained code necessary for verification.
22
23 HMAC.cry is a [Cryptol](http://www.cryptol.net/)
24 specification/implementation of HMAC. Cryptol can be seen as an
25 implementation because it is executable. It can be given a message and
26 a key as input, and produce output. It is a specification because the
27 cryptol language looks like the mathematical language that
28 cryptographers like to specify cryptography in. It does not have many
29 of the safety risks that a C program has, and it is typically much
30 easier to read and understand than a C program.
31
32 HMAC.saw is a [SAWScript](https://github.com/GaloisInc/saw-script)
33 file that defines the relationship between the previous two files. It
34 defines an equivalence between the HMAC functions that live in
35 all_llvm.bc and the HMAC functions that are in HMAC.cry. It then gives
36 instructions for how automated solvers can be used to prove this
37 equivalence. When run with the command `saw HMAC.saw`, this file loads
38 in the other two and proves the HMAC files equivalent.
39
40 ## The build
41
42 Running the saw tests will require a SAW executable, which must be able
43 to find the Yices and Z3 provers on the path. Future examples might
44 require further installation of provers. The build will also require
45 clang, which is not currently a necessary prerequisite for s2n.
46
47 We have integrated the build of this test into the s2n build. Right
48 now, the steps for a build are (files that do the work are listed in parenthesis):
49
50 1. patch s2n to prepare it for SAW, when necessary (currently not
51 necessary) (s2n/Makefile)
52 2. compile all files in s2n/crypto to llvm bitcode (located in
53 s2n/tests/saw/bitcode) using the clang
54 compiler, (s2n/crypto/Makefile, sn2/s2n.mk)
55 3. link the files in s2n/tests/saw/bitcode into all_llvm.bc using
56 llvm-link (s2n/crypto/Makefile)
57 4. enter the test directory and run all of the saw scripts that are
58 in the s2n/tests/saw directory, checking and logging the results
59 (s2n/Makefile, s2n/tests/makefile, s2n/tests/saw) and
60 5. enable cleaning for compiled bitcode and test logs. all bitcode
61 (.bc) in any source directories will be cleaned, but logs (.log)
62 will only be cleaned out of the saw directory. On recommendation,
63 it's trivial to switch the behavior for either.
64 (s2n/tests/Makefile, s2n/tests/saw)
65
66 With the exception of step 5 (`make clean`), all of these steps are run
67 by running `make saw` in the s2n root directory. The only modification
68 needed for a Travis script is to install Yices and Z3, download SAW, and
69 run the SAW make target.