21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 6-1. The Davies-Meyer construct<br />

Traditionally, hash functions pad by appending a bit with a value of 1, then however<br />

many zeros are necessary to align to the next block of input. Input is typically<br />

strengthened by adding a block of data to the end that encodes the message length.<br />

Nonetheless, such strengthening does not protect against length-extension attacks.<br />

(To prevent against those, see Recipe 6.7.)<br />

Matyas-Meyer-Oseas is a similar construction that is preferable in that the plaintext<br />

itself is not used as the key to a block cipher (this could make related-key attacks on<br />

Davies-Meyer easier); we’ll present that as a component when we show how to<br />

implement MDC-2 in Recipe 6.16.<br />

Here is an example API for using Davies-Meyer wihtout a nonce:<br />

void spc_dm_init(SPC_DM_CTX *c);<br />

void spc_dm_update(SPC_DM_CTX *c, unsigned char *msg, size_t len);<br />

void spc_dm_final(SPC_DM_CTX *c, unsigned char out[SPC_BLOCK_SZ]);<br />

The following is an implementation using AES-128. This code requires linking<br />

against an AES implementation, and it also requires that the macros developed in<br />

Recipe 5.5 be defined (they bridge the API of your AES implementation with this<br />

book’s API).<br />

#include <br />

#include <br />

#ifndef WIN32<br />

#include <br />

#include <br />

#include <br />

#else<br />

#include <br />

#include <br />

#endif<br />

#define SPC_KEY_SZ 16<br />

P i<br />

typedef struct {<br />

unsigned char h[SPC_BLOCK_SZ];<br />

292 | Chapter 6: Hashes and Message Authentication<br />

IV i–1<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

E<br />

IV i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!