-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SAW proofs for integration of Arm proofs for SHA384 (#128)
This PR extends existing SHA384/512 proofs to support Arm LLVM IR. This work fulfills the integration of Arm assembly proofs in #122 . Specifically, this PR: 1. Adds a new workflow called SAW_aarch64 that compiles aws-lc to AArch64 LLVM IR and run SHA384 proofs with the AAarch64 LLVM IR 2. The SAW proofs are refactored to two sets of proofs: For X86_64: verify-SHA384-x86.saw and verify-SHA512-x86.saw For AAarch64: verify-SHA384-aarch64-neoverse-n1.saw, verify-SHA384-aarch64-neoverse-v1.saw, verify-SHA512-aarch64-neoverse-n1.saw and verify-SHA512-aarch64-neoverse-v1.saw (currently SHA512 proofs are disabled due to a safety check issue) 3. A set of shell scripts are written to support the workflow
- Loading branch information
Showing
58 changed files
with
593 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: 'AWS-LC Formal Verification SAW Proofs' | ||
description: 'Check SAW proofs to verify AWS-LC against Cryptol specs' | ||
runs: | ||
using: 'docker' | ||
image: '../../../Dockerfile.saw_aarch64' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# AWS libcrypto Verification using Coq | ||
Proofs in this directory are carried out in Coq. SAW supports exporting Cryptol specifications to Coq. We use Coq to conduct verification of the Cryptol specifications that are not achievable within Cryptol. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
FROM ubuntu:20.04 | ||
ENV GOROOT=/usr/local/go | ||
ENV PATH="$GOROOT/bin:$PATH" | ||
ARG GO_VERSION=1.20.1 | ||
ARG GO_ARCHIVE="go${GO_VERSION}.linux-amd64.tar.gz" | ||
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections | ||
RUN apt-get update | ||
RUN apt-get install -y curl wget unzip git cmake ninja-build clang llvm g++-aarch64-linux-gnu \ | ||
lld python3-pip file time python3-pkgconfig libgmp-dev opam | ||
|
||
RUN wget "https://dl.google.com/go/${GO_ARCHIVE}" && tar -xvf $GO_ARCHIVE && \ | ||
mkdir $GOROOT && mv go/* $GOROOT && rm $GO_ARCHIVE | ||
|
||
RUN pip3 install psutil | ||
|
||
# Dependencies for Cryptol-Air-Interface | ||
# ghcup, ghc-8.10.7 | ||
# zlib: libghc-bzlib-dev zlib1g-dev | ||
|
||
ADD ./SAW/scripts/aarch64 /lc/scripts | ||
RUN /lc/scripts/docker_install.sh | ||
ENV CRYPTOLPATH="../../../../cryptol-specs:../../../cryptol-specs:../cryptol-specs:../../spec:./spec" | ||
|
||
# This container expects all files in the directory to be mounted or copied. | ||
# The GitHub action will mount the workspace and set the working directory of the container. | ||
# Another way to mount the files is: docker run -v `pwd`:`pwd` -w `pwd` <name> | ||
|
||
ENTRYPOINT ["./SAW/scripts/aarch64/docker_entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# AWS libcrypto Verification using NSym | ||
Proofs in this directory are carried out in NSym using [Cryptol](https://cryptol.net/) specifications. Cryptol specifications are automatically translated into Ocaml to be used in NSym proofs. The NSym proofs cover the verification of Arm assembly programs. | ||
|
||
## Safety Guarantee in NSym proofs | ||
|
||
* Memory region accesses are aligned and inbound. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
# Autospecs | ||
|
||
This dune package contains automatically generated Ocaml specifications and auxiliary Ocaml files associated with the automatically generated specifications. We use Cryptol specifications (for SAW proofs) as input and translate them into Ocaml specifications that work with NSym. Auxiliary Ocaml files contain functions or lemmas that are needed in the NSym proofs. We keep the automatically generated files in the repository to keep a record of them. | ||
This dune package contains automatically generated Ocaml specifications. We use Cryptol specifications (for SAW proofs) as input and translate them into Ocaml specifications that work with NSym. We keep the automatically generated files in the repository to keep a record of them. | ||
|
||
## SHA512 | ||
|
||
The automatically generated specifications include: | ||
1. `SHA384rec.ml`: A translation from NSym/spec/SHA384rec.cry | ||
2. `SHA512rec.ml`: A translation from NSym/spec/SHA512rec.cry | ||
|
||
The auxiliary files are: | ||
1. `sha2.ml`: A parameterization of the NSym proofs to allow both SHA384 and SHA512 | ||
2. `sha512rec_theorems.ml`: Base case and inductive case theorems for the recursive function `air_processBlocks_rec` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
:l SHA384rec.cry | ||
|
||
:l SHA384recEquiv.cry | ||
:prove processBlock_Common_equiv | ||
|
||
:l SHA384rec.cry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module SHA384recEquiv where | ||
|
||
import Primitive::Keyless::Hash::SHA384 as SHA384 | ||
import SHA384rec as SHA384rec | ||
import Array | ||
import Common::ByteArray | ||
|
||
type WordArray = Array[64][64] | ||
type w = SHA384rec::w | ||
|
||
// Proving the NSym processBlock_Common_rec is equivalent to cryptol-specs processBlock_Common | ||
property processBlock_Common_equiv (H : [8*w]) (Mi : [16][w]) = | ||
join (SHA384::processBlock_Common (split H) Mi) == SHA384rec::processBlock_Common_rec H w0 w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 | ||
where [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15] = Mi | ||
|
||
// The function processBlocks is a recursive/loop structure over processBlock_Common. | ||
// Likewise, the function processBlocks_rec is a recursive structure over | ||
// processBlock_Common_rec. | ||
// Having verified the equivalence between processBlock_Common and | ||
// processBlock_Common_rec, we then state the lemma for the top-level loop strucures. | ||
// Manual inspection is only required for the loop structure. | ||
|
||
// This property could not be proved nor checked due to Cryptol's lack of support for loops and Arrays | ||
property processBlocks_equiv (H : [8*w]) (data : ByteArray) (data2 : WordArray) (n : [64]) = | ||
// This lemma lacks a hypothesis about the equivalence between data and data2 | ||
// This hypothesis requires quantifiers | ||
(join (SHA384::processBlocks (split H) data 0 n)) == (SHA384rec::processBlocks_rec H n data2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
:l SHA512recEquiv.cry | ||
:prove processBlock_Common_equiv | ||
|
||
:l SHA512rec.cry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module SHA512recEquiv where | ||
|
||
import Primitive::Keyless::Hash::SHA512 as SHA512 | ||
import SHA512rec as SHA512rec | ||
import Array | ||
import Common::ByteArray | ||
|
||
type WordArray = Array[64][64] | ||
type w = SHA512rec::w | ||
|
||
// Proving the NSym processBlock_Common_rec is equivalent to cryptol-specs processBlock_Common | ||
property processBlock_Common_equiv (H : [8*w]) (Mi : [16][w]) = | ||
join (SHA512::processBlock_Common (split H) Mi) == SHA512rec::processBlock_Common_rec H w0 w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 w14 w15 | ||
where [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15] = Mi | ||
|
||
// The function processBlocks is a recursive/loop structure over processBlock_Common. | ||
// Likewise, the function processBlocks_rec is a recursive structure over | ||
// processBlock_Common_rec. | ||
// Having verified the equivalence between processBlock_Common and | ||
// processBlock_Common_rec, we then state the lemma for the top-level loop strucures. | ||
// Manual inspection is only required for the loop structures. | ||
|
||
// This property could not be proved nor checked due to Cryptol's lack of support for loops and Arrays | ||
property processBlocks_equiv (H : [8*w]) (data : ByteArray) (data2 : WordArray) (n : [64]) = | ||
// This lemma lacks a hypothesis about the equivalence between data and data2 | ||
// This hypothesis requires quantifiers | ||
(join (SHA512::processBlocks (split H) data 0 n)) == (SHA512rec::processBlocks_rec H n data2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.