Cryptography

advertisement
CS 4020 – Computing and Social Responsibility
Programming Assignment #6
Applied Cryptography
Block Ciphers and Chaining Modes
Solve the problem described below in a programming language of your
choice. For this task you will need to use an external cryptographic library.
These cryptographic libraries have functions for the most common
cryptographic tasks, for example using a block cipher. Examples of such
libraries are:

Java (http://java.sun.com/javase/technologies/security/). Starting
from version 1.4 cryptography libraries have been integrated in Java
and you don’t have to install them separately (note however, that this
“default” support has some limitations regarding e.g. supported key
lengths for a particular cipher etc). Still it provides all the
cryptographic functions that you might need for this assignment.

OpenSSL (http://www.openssl.org). A library developed primarily for C
under UNIX, but which can be used also with Windows C compilers
(Microsoft Visual C++ and Borland compilers). This library contains all
the functionality necessary for solving the tasks for this assignment.
Precompiled packages for Windows (provided either as .dll or .exe
files) sometimes are available from 3rd party developers.
There are probably other libraries out there, and if you find one that suits
your needs, feel free to use it!
The task
Your task is to create a program that encrypts and decrypts a given text
using a symmetric block cipher of your choice (AES, DES, 3DES, IDEA
etc.) and encrypts/decrypts using the following chaining modes:

CBC chaining mode;

either CFB or OFB chaining mode (you can chose which one you
want).
The program should take as input a string of arbitrary length and a key,
encrypt (decrypt) the string using the key and output the result. You will
need to research information about the different chaining modes. The format
of the input and how the key is given is your choice, as well as what block
ciphers to use and the details of implementation of chaining modes.
For CBC mode it is required that the length of the output must be the
same as the length of the input. That is, you must deal with the
possibility that the input may not be an even multiple of the block length,
and you must implement a method of some sort to deal with this problem.
(However, you can assume that the length of the input will be at least the
size of one block.) As a consequence, you should assume that initialization
vector is constant for all encryptions (e.g. all bits are zeroes).
For CFB or OFB mode you should use a random initialization vector for
each encryption. As a result, your cipher text will be longer than plaintext;
however you still must deal with the possibility that the input may not be an
even multiple of the block length.
You can choose the details of the user interface in any way you like. The
string to encrypt/decrypt and the key used can be read from a file, given by
the user or just hard coded. Also, you must provide some tools for key
generation. You can use flags to switch between encryption/decryption and
chaining modes, or you can use different programs.
Formally, the requirements are the following:

Input: An arbitrary length string, a key, a choice of chaining mode
and a choice of whether to encrypt or decrypt.

Output: An encryption/decryption of the string under the specified
chaining mode with the specified key.
You also need to provide tools for generation of a random key (or, if you
wish, key derived from a pass-phrase). If your cryptographic library supports
it, using a “printable character format” (hexadecimal, Base64 etc.) for key
files is preferable.
Naturally, decrypting an encrypted string should give back the clear text. For
this task, you may use block ciphers from an external library, but you must
implement the chaining and the special processing of the last
block(s) by yourself. In other words, you may only use a function that
takes one block as input, performs regular encryption, and returns the
encrypted block. You don’t have to implement error handling of any kind.
You can assume that the format of the input is correct, and it is perfectly allright to crash on invalid input!
What to Hand In:
Email your source code files to barbara.hecker@csueastbay.edu with the
subject line of [your last name] + “Prog6”
Download