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.

output<br />

Buffer into which the plaintext is written. This buffer must always be at least<br />

ctlen - 16 bytes in size because the message shrinks by 16 bytes when the<br />

authentication value is removed.<br />

The cwc_cleanup( ) function simply wipes the contents of the cwc context object<br />

passed into it.<br />

See Also<br />

• CWC implementation from Brian Gladman: http://fp.gladman.plus.com/AES/<br />

cwc.zip<br />

• CWC home page: http://www.zork.org/cwc<br />

• Recipes 5.4, 5.5<br />

5.11 Manually Adding and Checking Cipher<br />

Padding<br />

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

You want to add padding to data manually, then check it manually when decrypting.<br />

Solution<br />

There are many subtle ways in which padding can go wrong, so use an off-the-shelf<br />

scheme, such as PKCS block cipher padding.<br />

Discussion<br />

Padding is applied to plaintext; when decrypting, you must check for<br />

proper padding of the resulting data to determine where the plaintext<br />

message actually ends.<br />

Generally, it is not a good idea to add padding yourself. If you’re using a reasonably<br />

high-level abstraction, padding will be handled for you. In addition, padding often<br />

isn’t required, for example, when using a stream cipher or one of many common<br />

block cipher modes (including CWC, CTR, CCM, OFB, and CFB).<br />

Because ECB mode really shouldn’t be used for stream-based encryption, the only<br />

common case where padding is actually interesting is when you’re using CBC mode.<br />

If you are in a situation where you do need padding, we recommend that you use a<br />

standard scheme. There are many subtle things that can go wrong (although the<br />

Manually Adding and Checking Cipher Padding | 205<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!