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.

CryptKey k(const byte ∗ bytes, uint16 num key bytes);<br />

initializes k with a copy of the array bytes of size num bytes.<br />

CryptKey k(const CryptByteString& byte str);<br />

initializes k with byte str.<br />

CryptKey k(const char ∗ hex str);<br />

initializes k with the hexadecimal representation in hex str.<br />

Key generation<br />

A key generation algorithm takes as input a (partially) secret seed s of arbitrary length<br />

and outputs a key k of the desired size. <strong>The</strong> gist of this process is to apply a secure hash<br />

function H to the seed and to use the returned hash value as the key, i.e. k = H(s). In<br />

our implementation we use the checksum of the SHACoder, which is 20 bytes long. Since<br />

we want to be able to generate a key of size n ≠ 20 we use the following approach: We<br />

divide the key into p = ⌈n/20⌉ portions k 1 , . . . , k p , where the size of k 1 , . . . , k p−1 is 20<br />

and the size of k p is at most 20. We set k i = H(s ◦ n ◦ i). (Here “x ◦ y” denotes the<br />

concatenation of x and y, and k p is possibly a proper suffix of the returned hash value.)<br />

<strong>The</strong>n we have k = k 1 ◦ . . . ◦ k p .<br />

<strong>The</strong> question is now what to use as seed for the key generation. <strong>The</strong> first idea that comes<br />

to mind is to use the passphrase supplied by the user. In that case the process would be<br />

vulnerable to the so-called dictionary attack. This works as follows: Since many users<br />

tend to choose their passphrases carelessly, the attacker builds a dictionary of common<br />

phrases and their corresponding keys. This gives him a set of “likely” keys which he<br />

tries first to break the system. One way to make this attack harder is to apply the hash<br />

function several times, i.e. instead of k = H(s) we set k = H(H(. . . H(s))). Even if<br />

we apply H some thousand times it does not slow down the generation of a single key<br />

noticably. However, it should slow the generation of a whole dictionary considerably.<br />

An even more effective counter measure is to use something that is called salt. This is a<br />

string which is appended to the passphrase to form the actual seed for the key generation.<br />

<strong>The</strong> salt does not have to be kept secret, the important point is that each key generation<br />

uses a different salt. So it is impossible to reuse a dictionary built for a specific salt. <strong>The</strong><br />

salt is also useful if you want to reuse a passphrase. E.g., if you want to authenticate and<br />

to encrypt a file you might refrain from remembering two different phrases. But since it is<br />

not a good idea to use the same key twice you could generate two different keys by using<br />

two different salts.<br />

CryptKey<br />

CryptKey :: generate key(uint16 key size,<br />

const CryptByteString& seed,<br />

uint32 num iterations)<br />

generates a key of size key size by applying a hash<br />

function num iterations times to the given seed.

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

Saved successfully!

Ooh no, something went wrong!