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.

work, which severely limits portability across various Windows versions. (The .NET<br />

framework is available only for Windows XP and Windows .NET Server 2003.)<br />

Brian Gladman’s AES implementation<br />

Brian Gladman has written the fastest freely available AES implementation to date.<br />

He has a version in x86 assembly that works with Windows and a portable C version<br />

that is faster than the assembly versions other people offer. It’s available from<br />

his web page at http://fp.gladman.plus.com/AES/.<br />

To bind his implementation to our macros, do the following:<br />

#include "aes.h"<br />

#define SPC_BLOCK_SZ 16<br />

typedef aes_ctx SPC_KEY_SCHED;<br />

#define SPC_ENCRYPT_INIT(sched, key, keybytes) aes_enc_key(key, keybytes, sched)<br />

#define SPC_DECRYPT_INIT(sched, key, keybytes) aes_dec_key(key, keybytes, sched)<br />

#define SPC_DO_ENCRYPT(sched, in, out) aes_enc_block(in, out, sched)<br />

#define SPC_DO_DECRYPT(sched, in, out) aes_dec_block(in, out, sched)<br />

OpenSSL block cipher implementations<br />

Next, we’ll provide implementations for these macros for all of the ciphers in<br />

OpenSSL0.9.7. Note that the block size for all of the algorithms listed in this section<br />

is 8 bytes, except for AES, which is 16.<br />

Table 5-2 lists the block ciphers that OpenSSLexports, along with the header file<br />

you need to include for each cipher and the associated type for the key schedule.<br />

Table 5-2. Block ciphers supported by OpenSSL<br />

Cipher Header file Key schedule type<br />

AES openssl/aes.h AES_KEY<br />

Blowfish openssl/blowfish.h BF_KEY<br />

CAST5 openssl/cast.h CAST_KEY<br />

DES openssl/des.h DES_key_schedule<br />

3-key Triple-DES openssl/des.h DES_EDE_KEY<br />

2-key Triple-DES openssl/des.h DES_EDE_KEY<br />

IDEA openssl/idea.h IDEA_KEY_SCHEDULE<br />

RC2 openssl/rc2.h RC2_KEY<br />

RC5 openssl/rc5.h RC5_32_KEY<br />

Table 5-3 provides implementations of the SPC_ENCRYPT_INIT macro for each of the<br />

block ciphers listed in Table 5-2.<br />

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

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

Using a Raw Block Cipher | 173

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

Saved successfully!

Ooh no, something went wrong!