From 89b9d4864327b6d05f00ac7b13c1437bae4b47bd Mon Sep 17 00:00:00 2001 From: h2-addad <hamza2.addad@live.uwe.ac.uk> Date: Sun, 16 Jul 2023 15:21:04 +0000 Subject: [PATCH] Upload New File --- src/tests/vm/page-linear.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/tests/vm/page-linear.c diff --git a/src/tests/vm/page-linear.c b/src/tests/vm/page-linear.c new file mode 100644 index 0000000..652a47b --- /dev/null +++ b/src/tests/vm/page-linear.c @@ -0,0 +1,44 @@ +/* Encrypts, then decrypts, 2 MB of memory and verifies that the + values are as they should be. */ + +#include <string.h> +#include "tests/arc4.h" +#include "tests/lib.h" +#include "tests/main.h" + +#define SIZE (2 * 1024 * 1024) + +static char buf[SIZE]; + +void +test_main (void) +{ + struct arc4 arc4; + size_t i; + + /* Initialize to 0x5a. */ + msg ("initialize"); + memset (buf, 0x5a, sizeof buf); + + /* Check that it's all 0x5a. */ + msg ("read pass"); + for (i = 0; i < SIZE; i++) + if (buf[i] != 0x5a) + fail ("byte %zu != 0x5a", i); + + /* Encrypt zeros. */ + msg ("read/modify/write pass one"); + arc4_init (&arc4, "foobar", 6); + arc4_crypt (&arc4, buf, SIZE); + + /* Decrypt back to zeros. */ + msg ("read/modify/write pass two"); + arc4_init (&arc4, "foobar", 6); + arc4_crypt (&arc4, buf, SIZE); + + /* Check that it's all 0x5a. */ + msg ("read pass"); + for (i = 0; i < SIZE; i++) + if (buf[i] != 0x5a) + fail ("byte %zu != 0x5a", i); +} -- GitLab