This is an old revision of the document!


Lab 09 - OpenSSL MACs and Hashes

Exercise 1

In this first exercise we'll see how to compute hashes using the OpenSSL command line interface.

You can interact with the OpenSSL utilities in two ways:

  • directly from bash, by using the openssl command followed by the desired command and parameters
  • from the OpenSSL console, by using the openssl command without additional arguments. You can close the console by calling quit or exit.

If the manual pages are correctly installed, you can consult the documentation via man <command_name> (e.g. man md5).

Hashes are often used to check the integrity of downloaded files. We will now use OpenSSL to compute the MD5 and SHA-1 hashes of this page.

Download this page by running:

linux$ wget http://ocw.cs.pub.ro/courses/sasc/laboratoare/09 -O sasc.html

Use OpenSSL to compute the MD5 and SHA-1 hashes of the newly downloaded file; print the output in hexadecimal.

To check your results, you can use md5sum or sha1sum as an alternative way of computing the same hashes.

Exercise 2

In this second exercise we'll use the command line to compute an HMAC, with SHA-1 as the hashing algorithm.

Recall from the lecture that for HMAC to be secure, we need to sample a random key $k \gets \mathcal{K}$.

We can generate random bytes using openssl rand. To compute HMACs, check the documentation for openssl dgst.

For this exercise, use OpenSSL commands to:

  1. generate a 16 byte random key
  2. use the key to compute the SHA-1 HMAC of the page downloaded in the previous exercise

Exercise 3

In this exercise you will implement the Birthday attack on SHA-1 from the previous lab using OpenSSL. The goal is to obtain a collision in the first four bytes of the hash.

In contrast to previous labs, this time we'll use C. You can implement the attack from scratch, or start from our archive here.

To compute a digest, you might find the code below useful:

    SHA_CTX context;
    SHA1_Init(&context);
    SHA1_Update(&context, buffer, length);
    SHA1_Final(md, &context); /* md must point to at least 20 bytes of valid memory */

To compile using OpenSSL you will need to install the development version of the library which includes the header files.

Download the library from https://www.openssl.org/source/old/1.0.1/openssl-1.0.1f.tar.gz, and unpack it.

Open the unpacked folder from bash, and run the following commands:

linux$ ./config --prefix=/home/student/local --openssldir=/home/student/local/openssl
linux$ make
linux$ make install

sasc/laboratoare/09.1462888269.txt.gz · Last modified: 2016/05/10 16:51 by sergiu.costea
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0