CS318 - Pintos
Pintos source browser for JHU CS318 course
page-linear.c
Go to the documentation of this file.
1 /** Encrypts, then decrypts, 2 MB of memory and verifies that the
2  values are as they should be. */
3 
4 #include <string.h>
5 #include "tests/arc4.h"
6 #include "tests/lib.h"
7 #include "tests/main.h"
8 
9 #define SIZE (2 * 1024 * 1024)
10 
11 static char buf[SIZE];
12 
13 void
14 test_main (void)
15 {
16  struct arc4 arc4;
17  size_t i;
18 
19  /* Initialize to 0x5a. */
20  msg ("initialize");
21  memset (buf, 0x5a, sizeof buf);
22 
23  /* Check that it's all 0x5a. */
24  msg ("read pass");
25  for (i = 0; i < SIZE; i++)
26  if (buf[i] != 0x5a)
27  fail ("byte %zu != 0x5a", i);
28 
29  /* Encrypt zeros. */
30  msg ("read/modify/write pass one");
31  arc4_init (&arc4, "foobar", 6);
32  arc4_crypt (&arc4, buf, SIZE);
33 
34  /* Decrypt back to zeros. */
35  msg ("read/modify/write pass two");
36  arc4_init (&arc4, "foobar", 6);
37  arc4_crypt (&arc4, buf, SIZE);
38 
39  /* Check that it's all 0x5a. */
40  msg ("read pass");
41  for (i = 0; i < SIZE; i++)
42  if (buf[i] != 0x5a)
43  fail ("byte %zu != 0x5a", i);
44 }
lib.h
SIZE
#define SIZE
Encrypts, then decrypts, 2 MB of memory and verifies that the values are as they should be.
Definition: page-linear.c:9
arc4
Alleged RC4 algorithm encryption state.
Definition: arc4.h:8
string.h
arc4_init
void arc4_init(struct arc4 *arc4, const void *key_, size_t size)
Definition: arc4.c:14
arc4_crypt
void arc4_crypt(struct arc4 *arc4, void *buf_, size_t size)
tests/arc4.h
Definition: arc4.c:35
arc4.h
arc4::i
uint8_t i
Definition: arc4.h:11
fail
void fail(const char *format,...)
Definition: lib.c:40
buf
static char buf[SIZE]
Definition: page-linear.c:11
main.h
msg
void msg(const char *format,...)
Definition: lib.c:28
memset
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
Definition: string.c:279
test_main
void test_main(void)
tests/main.h
Definition: page-linear.c:14