aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/vm/child-linear.c
blob: eca3e3f5a19dac0305319104ae15f5e8cb0e7ea5 (plain) (blame)
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
/* Child process of page-parallel.
   Encrypts 1 MB of zeros, then decrypts it, and ensures that
   the zeros are back. */

#include <string.h>
#include "tests/arc4.h"
#include "tests/lib.h"
#include "tests/main.h"

const char *test_name = "child-linear";

#define SIZE (1024 * 1024)
static char buf[SIZE];

int
main (int argc, char *argv[])
{
  const char *key = argv[argc - 1];
  struct arc4 arc4;
  size_t i;

  /* Encrypt zeros. */
  arc4_init (&arc4, key, strlen (key));
  arc4_crypt (&arc4, buf, SIZE);

  /* Decrypt back to zeros. */
  arc4_init (&arc4, key, strlen (key));
  arc4_crypt (&arc4, buf, SIZE);

  /* Check that it's all zeros. */
  for (i = 0; i < SIZE; i++)
    if (buf[i] != '\0')
      fail ("byte %zu != 0", i);

  return 0x42;
}