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.

Once those bindings are made, the Zork CWC implementation has a simple API that<br />

accepts an entire message at once:<br />

int cwc_init(cwc_t ctx[1], u_char key[ ], int keybits);<br />

void cwc_encrypt_message(cwc_t ctx[1], u_char a[ ], u_int32 alen, u_char pt[ ],<br />

u_int32 ptlen, u_char nonce[11], u_char output[ ]);<br />

int cwc_decrypt_message(cwc_t ctx[1], u_char a[ ], u_int32 alen, u_char ct[ ],<br />

u_int32 ctlen, u_char nonce[11], u_char output[ ]);<br />

void cwc_cleanup(cwc_t ctx[1]);<br />

If you have very large messages, this API insists that you buffer them before encrypting<br />

or decrypting. That’s not a fundamental limitation of CWC mode, but only of<br />

this implementation. A future version of the implementation might change that, but<br />

do note that it would require partially decrypting a message before the library could<br />

determine whether the message is authentic. The API above does not decrypt if the<br />

message isn’t authentic.<br />

If you need to operate on very large messages, check out Brian Gladman’s<br />

CWC implementation, which works incrementally.<br />

This API looks slightly different from the all-in-one APIs we’ve presented for other<br />

modes in this chapter. It’s actually closer to the incremental mode. The CWC mode<br />

has a notion of individual messages. It is intended that each message be sent individually.<br />

You’re expected to use a single key for a large number of messages, but each<br />

message gets its own nonce. Generally, each message is expected to be short but can<br />

be multiple gigabytes.<br />

Note that encrypting a message grows the message by 16 bytes. The extra 16 bytes at<br />

the end are used for ensuring the integrity of the message (it is effectively the result of<br />

a message authentication code; see Chapter 6).<br />

The previous API assumes that you have the entire message to encrypt or decrypt at<br />

once. In the following discussion, we’ll talk about the API that allows you to incrementally<br />

process a single message.<br />

The cwc_init( ) function allows us to initialize a CWC context object of type cwc_t<br />

that can be reused across multiple messages. Generally, a single key will be used for<br />

an entire session. The first argument is a pointer to the cwc_t object (the declaration<br />

as an array of one is a specification saying that the pointer is only to a single object<br />

rather than to an array of objects). The second argument is the AES key, which must<br />

be a buffer of 16, 24, or 32 bytes. The third argument specifies the number of bits in<br />

the key (128, 192 or 256). The function fails if keybits is not a correct value.<br />

The cwc_encrypt_message( ) function has the following arguments:<br />

ctx<br />

Pointer to the cwc_t context object.<br />

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

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

Using CWC Mode | 203

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

Saved successfully!

Ooh no, something went wrong!