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.

*len = 0;<br />

outbuf = 0;<br />

}<br />

return outbuf;<br />

}<br />

The public API to this code is:<br />

unsigned char *spc_base64_decode(unsigned char *buf, size_t *len, int strict, int<br />

*err);<br />

The API assumes that buf is a NULL-terminated string. The len parameter is a pointer<br />

that receives the length of the binary output. If there is an error, the memory pointed<br />

to by len will be 0, and the value pointed to by err will be non-zero. The error will be<br />

-1 if there is a padding error, -2 if strict checking was requested, but a character outside<br />

the strict set is found, and -3 if malloc( ) fails.<br />

See Also<br />

Recipe 4.5<br />

4.7 Representing Keys (or Other Binary Data)<br />

as English Text<br />

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

You want to use an easy-to-read format for displaying keys (or fingerprints or some<br />

other interesting binary data). English would work better than a hexadecimal representation<br />

because people’s ability to recognize the key as correct by sight will be better.<br />

Solution<br />

Map a particular number of bits to a dictionary of words. The dictionary should be<br />

of such a size that an exact mapping to a number of bits is possible. That is, the dictionary<br />

should have a number of entries that is a power of two.<br />

Discussion<br />

The spc_bin2words() function shown here converts a binary string of the specified<br />

number of bytes into a string of English words. This function takes two arguments:<br />

str is the binary string to convert, and len is the number of bytes to be converted.<br />

#include <br />

#include <br />

#include "wordlist.h"<br />

#define BITS_IN_LIST 11<br />

128 | Chapter 4: Symmetric Cryptography Fundamentals<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!