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.

most important requirement is that padding always be unambiguous *), and there’s<br />

no good reason to wing it.<br />

The most widespread standard padding for block ciphers is called PKCS block padding.<br />

The goal of PKCS block padding is that the last byte of the padded plaintext<br />

should unambiguously describe how much padding was added to the message. PKCS<br />

padding sets every byte of padding to the number of bytes of padding added. If the<br />

input is block-aligned, an entire block of padding is added. For example, if four bytes<br />

of padding were needed, the proper padding would be:<br />

0x04040404<br />

If you’re using a block cipher with 64-bit (8-byte) blocks, and the input is blockaligned,<br />

the padding would be:<br />

0x0808080808080808<br />

Here’s an example API for adding and removing padding:<br />

void spc_add_padding(unsigned char *pad_goes_here, int ptlen, int bl) {<br />

int i, n = (ptlen - 1) % bl + 1;<br />

}<br />

for (i = 0; i < n; i++) *(pad_goes_here + i) = (unsigned char)n;<br />

int spc_remove_padding(unsigned char *lastblock, int bl) {<br />

unsigned char i, n = lastblock[bl - 1];<br />

unsigned char *p = lastblock + bl;<br />

/* In your programs you should probably throw an exception or abort instead. */<br />

if (n > bl || n

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

Saved successfully!

Ooh no, something went wrong!