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.

6.9 Checking Message Integrity<br />

<strong>Problem</strong><br />

You want to provide integrity for messages in such a way that people with a secret<br />

key can verify that the message has not changed since the integrity value (often called<br />

a tag) was first calculated.<br />

Solution<br />

Use a message integrity check. As with hash functions, there are somewhat standard<br />

interfaces, particularly an incremental interface.<br />

Discussion<br />

Libraries that support MACs tend to support incremental operation using a standard<br />

structure, very similar to that used by hash functions:<br />

1. Allocate and key a context object. The context object holds the internal state of<br />

the MAC until data processing is complete. The type of the context object can be<br />

specific to the MAC, or there can be a single type that works for all hash functions<br />

in a library. OpenSSLsupports only one MAC and has only the associated<br />

context type. The key can be reused numerous times without reallocating.<br />

Often, you will need to specify the underlying algorithm you are using for your<br />

MAC.<br />

2. Reset the context object, setting the internal parameters of the MAC to their initial<br />

state so that another message’s authentication tag can be calculated. Many<br />

MACs accept a nonce, and this is where you would pass that in. This is often<br />

combined with the “init” call when the algorithm does not take a nonce, such as<br />

with OMAC and HMAC.<br />

3. “Update” the context object by passing in data to be authenticated and the associated<br />

length of that input. The results of the MAC’ing process will be dependent<br />

on the order of the data that you pass, but you can pass in all the partial<br />

data you wish. That is, calling the update routine with the strings “he” then “llo”<br />

would produce the same results as calling it once with the string “hello”. The<br />

update function generally takes as arguments the context object, the data to process,<br />

and the associated length of that data.<br />

4. “Finalize” the context object and produce the authentication tag. Most APIs will<br />

generally take as arguments the context object and a buffer into which the message<br />

digest is placed.<br />

Often, you may have a block cipher or a hash function that you’d like to turn into a<br />

MAC, but no associated code comes with the cryptographic primitive. Alternately,<br />

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

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!