Deadline: October 24th, 2014.

1   Instructions

You must implement a program cryptserv working as follows.

cryptserv must takes two command-line arguments; a numeric encryption/decryption key, and a filesystem path to use as Unix domain socket (PF_UNIX/AF_UNIX). It must then listen for connections on that socket. When a client connects, cryptserv must encrypt/decrypt the received data stream from that client (cf Cryptography below) and send the results back to the client. The program must support exchanging data with multiple clients simultaneously.

For extra credits you may implement the following:


2   Cryptography

The encryption (or decryption) of the data stream from one client must use the following algorithm:

Be sure that each client connection uses its own random state!

3   Example use

The following examples uses Netcat (nc), a quasi-standard “swiss army” network tool:

# in one session
$ ./cryptserv 0xdeadbeef /tmp/mysock

# in another session
$ echo hello >msg.txt
$ nc -U /tmp/mysock <msg.txt >msg.enc
$ nc -U /tmp/mysock <msg.enc >msg2.txt
$ cmp msg.txt msg.enc || echo OK
$ cmp msg.txt msg2.txt && echo OK

# in yet another session
$ nc -U /tmp/mysock </dev/urandom >/dev/null &
$ echo hello | nc -U /tmp/mysock && echo OK

4   Grading