21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

To ensure that you choose the right cryptographic protocols for your<br />

application, you need an understanding of these basics. However,<br />

you’ll very rarely need to go all the way back to the primitive algorithms<br />

we discuss in these chapters. Instead, you should focus on outof-the-box<br />

protocols that are believed to be cryptographically strong.<br />

While we therefore recommend that you thoroughly understand the<br />

material in these chapters, we advise you to go to the recipes in<br />

Chapter 9 to find something appropriate before you come here and<br />

build something yourself. Don’t fall into the same trap that many of<br />

Applied Cryptography’s readers have fallen into!<br />

There are two classes of symmetric primitives, both of utmost importance. First are<br />

symmetric encryption algorithms, which provide for data secrecy. Second are message<br />

authentication codes (MACs), which can ensure that if someone tampers with data<br />

while in transit, the tampering will be detected. Recently, a third class of primitives<br />

has started to appear: encryption modes that provide for both data secrecy and message<br />

authentication. Such primitives can help make the application of cryptography<br />

less prone to disastrous errors.<br />

In this chapter, we will look at how to generate, represent, store, and distribute symmetric-key<br />

material. In Chapter 5, we will look at encryption using block ciphers<br />

such as AES, and in Chapter 6, we will examine cryptographic hash functions (such<br />

as SHA1) and MACs.<br />

Towards the end of this chapter, we do occasionally forward-reference<br />

algorithms from the next two chapters. It may be a good idea to<br />

read Recipes 5.1 through 5.4 and 6.1 through 6.4 before reading Recipes<br />

4.10 through 4.14.<br />

4.1 Representing Keys for Use in Cryptographic<br />

Algorithms<br />

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

You need to keep an internal representation of a symmetric key. You may want to<br />

save this key to disk, pass it over a network, or use it in some other way.<br />

Solution<br />

Simply keep the key as an ordered array of bytes. For example:<br />

/* When statically allocated */<br />

unsigned char *key[KEYLEN_BYTES];<br />

/* When dynamically allocated */<br />

unsigned char *key = (unsigned char *)malloc(KEYLEN_BYTES);<br />

Representing Keys for Use in Cryptographic Algorithms | 117<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!