PKUOS - Pintos
Pintos source browser for PKU Operating System 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
11static char buf[SIZE];
12
13void
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);
33
34 /* Decrypt back to zeros. */
35 msg ("read/modify/write pass two");
36 arc4_init (&arc4, "foobar", 6);
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}
void arc4_init(struct arc4 *arc4, const void *key_, size_t size)
Definition: arc4.c:14
void arc4_crypt(struct arc4 *arc4, void *buf_, size_t size)
tests/arc4.h
Definition: arc4.c:35
void fail(const char *format,...)
Definition: lib.c:40
void msg(const char *format,...)
Definition: lib.c:28
#define SIZE
Encrypts, then decrypts, 2 MB of memory and verifies that the values are as they should be.
Definition: page-linear.c:9
static char buf[SIZE]
Definition: page-linear.c:11
void test_main(void)
tests/main.h
Definition: page-linear.c:14
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
Definition: string.c:279
Alleged RC4 algorithm encryption state.
Definition: arc4.h:9
uint8_t i
Definition: arc4.h:11