summaryrefslogtreecommitdiffstats
path: root/security/nss/automation/saw/chacha20.saw
blob: 92145ab74ffec6920cd0757b5756a66b91b2d7a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import "chacha20.cry" as chacha20;

print "Proving ChaCha20 spec...";
prove_print abc {{ chacha20::allTestsPass }};

print "Loading LLVM bitcode...";
m <- llvm_load_module "../../../dist/Debug/lib/libfreeblpriv3.so.bc";

let SpecChaCha20 n = do {
  llvm_ptr "output" (llvm_array n (llvm_int 8));
  output <- llvm_var "*output" (llvm_array n (llvm_int 8));

  llvm_ptr "plain" (llvm_array n (llvm_int 8));
  plain <- llvm_var "*plain" (llvm_array n (llvm_int 8));

  len <- llvm_var "len" (llvm_int 32);
  llvm_assert_eq "len" {{ `n : [32] }};

  llvm_ptr "k" (llvm_array 32 (llvm_int 8));
  k <- llvm_var "*k" (llvm_array 32 (llvm_int 8));

  llvm_ptr "n1" (llvm_array 12 (llvm_int 8));
  n1 <- llvm_var "*n1" (llvm_array 12 (llvm_int 8));

  ctr <- llvm_var "ctr" (llvm_int 32);

  llvm_ensure_eq "*output" {{ chacha20::encrypt k ctr n1 plain }};

  llvm_verify_tactic abc;
};

print "Proving equality for a single block...";
time (llvm_verify m "Hacl_Chacha20_chacha20" [] (SpecChaCha20 64));

print "Proving equality for multiple blocks...";
time (llvm_verify m "Hacl_Chacha20_chacha20" [] (SpecChaCha20 256));