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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10.1 Secure Byte String ( CryptByteString )<br />

1. Definition<br />

An instance s of the class CryptByteString is basically a string of bytes. When s is not<br />

used anymore its memory is wiped out (by overwriting it a couple of times) before the<br />

memory is freed and returned to the system. <strong>The</strong> goal is to prevent an attacker from<br />

reading security sensitive data after your process has terminated. We want to point out<br />

that this mechanism can be foiled by the operating system: If it swaps the memory<br />

occupied by s to a swap file on a hard disc then the data will not be erased by s. (Some<br />

platforms offer to lock certain parts of the memory against swapping. CryptByteString<br />

uses this feature on Windows NT/2000/XP to protect its memory.)<br />

As we have stated above s can be used like a string or an array of bytes. <strong>The</strong> size n of s<br />

is the number of bytes in s, they are indexed from 0 to n − 1.<br />

Important: If you create a CryptByteString s from a C-style array or a string, or if you<br />

convert s to a string, then only the memory of s will be wiped out but not the memory<br />

of the array or the string.<br />

#include < <strong>LEDA</strong>/coding/crypt key.h ><br />

2. Creation<br />

CryptByteString s;<br />

creates an empty string.<br />

CryptByteString s(uint16 size);<br />

creates a string of the given size. All bytes in s are set to zero.<br />

CryptByteString s(const byte ∗ bytes, uint16 num bytes);<br />

CryptByteString s(const char ∗ str);<br />

creates a copy of the array bytes of size num bytes.<br />

creates a copy of the C-style string str. (<strong>The</strong> ’\0’ character at the<br />

end is not copied.)<br />

3. Operations<br />

uint16 s.get size( ) returns the size of s.<br />

bool s.is empty( ) returns true iff s is empty.<br />

void s.clear( ) makes s the empty string.<br />

const byte∗ s.get bytes( ) returns the internal byte-array of s.<br />

byte& s[uint16 idx] returns the byte at position idx.<br />

Precondition: 0 ≤ idx ≤ s.get size() − 1.

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

Saved successfully!

Ooh no, something went wrong!