// 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_encrypt" [] (SpecChaCha20 64));

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