31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

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.

10.4 Example for a Stream-Cipher ( CBCCoder )<br />

1. Definition<br />

A stream-cipher is a coder that encrypts and decrypts data streams. In this section<br />

we discuss the interface of such a coder by an example: CBCCoder< BlkCipher >. Every<br />

stream-cipher in <strong>LEDA</strong> uses a block-cipher BlkCipher which is specified as a template<br />

parameter. (More information about stream-ciphers and block-ciphers can be found<br />

in Section 10.3.) <strong>The</strong> following stream-ciphers are available: ECBCoder, CBCCoder,<br />

CFBCoder and OFBCoder. All of them, except for OFBCoder, support fast seek operations<br />

(see Section 9.22). <strong>The</strong> available block-ciphers are: Blowfish, Twofish and Rijndael.<br />

#include < <strong>LEDA</strong>/coding/stream ciphers.h ><br />

2. Creation<br />

CBCCoder< BlkCipher > C(streambuf ∗ src stream = 0, streambuf ∗ tgt stream = 0,<br />

bool own streams = false);<br />

creates an instance C which uses the given source and target<br />

streams. If own streams is set, then C is responsible for the destruction<br />

of the streams, otherwise the pointers src stream and tgt stream<br />

must be valid during the life-time of C.<br />

CBCCoder< BlkCipher > C(const char ∗ src file name, const char ∗ tgt file name);<br />

creates an instance C which uses file-streams for input and output.<br />

3. Operations<br />

Standard Operations<br />

void C.encode( ) encodes the source stream and writes the output to<br />

the target stream.<br />

void C.decode( ) decodes the source stream and writes the output to<br />

the target stream.<br />

uint32<br />

C.calculate length of encoded data(uint32 input length)<br />

calculates the length (in bytes) of the output when<br />

encoding some input of the given length with the current<br />

settings. (This function is helpful for encoding<br />

memory chunks (see below).)

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

Saved successfully!

Ooh no, something went wrong!