summaryrefslogtreecommitdiff
path: root/security/nss/automation/saw/poly1305.saw
blob: 44be1e3e0c441fb6d42c1f5b9fdfe081c527358f (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
41
42
43
44
45
46
47
// 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 "poly1305.cry" as poly1305;

print "Proving Poly1305 spec...";
prove_print abc {{ poly1305::allTestsPass }};

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

let SpecPoly1305 n = do {
  llvm_ptr "out" (llvm_array 16 (llvm_int 8));
  out <- llvm_var "*out" (llvm_array 16 (llvm_int 8));

  llvm_ptr "ad" (llvm_array 16 (llvm_int 8));
  ad <- llvm_var "*ad" (llvm_array 16 (llvm_int 8));

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

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

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

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

  llvm_assert_eq "*ad" {{ zero : [16][8] }};
  llvm_assert_eq "adLen" {{ 16 : [32] }};

  llvm_assert_eq "*ciphertext" {{ zero : [n][8] }};
  llvm_assert_eq "ciphertextLen" {{ `n : [32] }};

  llvm_assert_eq "*key" {{ zero : [32][8] }};

  let res = {{ poly1305::Poly1305 (ad # ciphertext # [16, 0, 0, 0, 0, 0, 0, 0] # [`n, 0, 0, 0, 0, 0, 0, 0]) (take`{16} key) (drop`{16} key) }};
  llvm_ensure_eq "*out" {{ res }};

  llvm_verify_tactic abc;
};

print "Proving equality for a single block...";
// This is currently disabled as it takes way too long. We need to help Z3
// prove this before we can enable it on Taskcluster.
//time (llvm_verify m "Poly1305Do" [] (SpecPoly1305 16));