YAPET::Key Class Reference

Converts the password into the key. More...

#include <key.h>

List of all members.

Public Member Functions

const uint8_t * getIVec () const
 Gets the initialization vector.
const uint8_t * getIVec (int &ivec_len) const
 Gets the pointer to the initialization vector.
const uint8_t * getKey () const
 Gets the pointer to the key.
const uint8_t * getKey (int &key_len) const
 Gets the pointer to the key.
uint32_t ivec_size () const
 Returns the length of the initialization vector.
 Key (const Key &k)
 Key (const char *password) throw (YAPETException)
 Initializes the key.
 operator const uint8_t * () const
 Cast operator.
 operator uint8_t * ()
 Cast operator.
bool operator!= (const Key &k) const
 Compares two keys for inequality.
const uint8_t * operator() () const
 Gets the pointer to the key.
const uint8_t * operator() (int &key_len) const
 Gets the pointer to the key.
const Keyoperator= (const Key &k)
bool operator== (const Key &k) const
 Compares two keys for equality.
uint32_t size () const
 Returns the key length in bytes.
 ~Key ()

Private Types

enum  {
  KEYLENGTH = 56, MD5_LEN = 16, SHA1_LEN = 20, RIPEMD160_LEN = 20,
  IVECLENGTH = 8
}

Private Member Functions

void cleanup ()
 Cleanup routine.

Private Attributes

uint8_t IVec [IVECLENGTH]
 Holds the initialization vector.
uint8_t key [KEYLENGTH]
 Holds the key.


Detailed Description

Converts the password into the key which is used by the other cryptographic related classes.

The key uses the maximum length of 448bits (56bytes) allowed for blowfish.

The key is computed using three passes. The first pass hashes the password using the sha1 algorithm. This hash is then re-hashed using md5 which is then appended to the key generated by the previous pass (sha1 + md5). The last pass hashes the result of the former two passes using RIPEMD-160 and appended the result to the key (sha1 + md5 + ripemd160).

The initialization vector is computed by hashing the key using the md5 algorithm and taking only the first eight bytes.

Definition at line 74 of file key.h.


Member Enumeration Documentation

anonymous enum [private]

Enumerator:
KEYLENGTH  The max length of the blowfish key in bytes (448 bits)
MD5_LEN  The length of the output of md5 (128 bits)
SHA1_LEN  The length of the output of sha1 (160 bits)
RIPEMD160_LEN  The lenght of the output of ripemd-160 (160 bits)
IVECLENGTH  The length of the initialization vector

Definition at line 76 of file key.h.


Constructor & Destructor Documentation

Key::Key ( const char *  password  )  throw (YAPETException)

Initializes the key and the initialization vector. Make sure you securely destroy the password provided to this method.

Parameters:
password a pointer to the location the password is stored. The password has to be zero-terminated.

Definition at line 57 of file key.cc.

Key::Key ( const Key k  ) 

Definition at line 235 of file key.cc.

References IVec, IVECLENGTH, key, and KEYLENGTH.

Key::~Key (  ) 

Definition at line 240 of file key.cc.

References cleanup().


Member Function Documentation

void Key::cleanup (  )  [private]

It clears the memory occupied by the key and the initialization vector by setting it to zero.

Definition at line 45 of file key.cc.

References IVec, IVECLENGTH, key, and KEYLENGTH.

Referenced by operator=(), and ~Key().

const uint8_t* YAPET::Key::getIVec (  )  const [inline]

Gets the initialization vector. Please remember that the initialization vector is not \0 terminated. So make sure you read only as many bytes as returned by ivec_size().

Returns:
pointer to the array of unsigned 8bit integers holding the initialization vector.

Definition at line 183 of file key.h.

References IVec.

const uint8_t* YAPET::Key::getIVec ( int &  ivec_len  )  const [inline]

Gets the initialization vector and its length. Please remember that the initialization vector is not \0 terminated. So make sure you read only ivec_len bytes from the pointer returned.

Parameters:
ivec_len a reference to an integer receiving the length of the initialization vector.
Returns:
pointer to the array of unsigned 8bit integers holding the initialization vector.

Definition at line 167 of file key.h.

References IVec, and IVECLENGTH.

Referenced by YAPET::Crypt::decrypt(), and YAPET::Crypt::encrypt().

const uint8_t* YAPET::Key::getKey (  )  const [inline]

Returns the key only. Please note that the key is not terminated by \0, so make sure you read only as many bytes as returned by size().

Returns:
pointer to the array of usigned 8bit integers holding the key.

Definition at line 151 of file key.h.

References key.

Referenced by operator()().

const uint8_t* YAPET::Key::getKey ( int &  key_len  )  const [inline]

Returns the key and its length. The key is not terminated by \0. So make sure you read only key_len bytes from the pointer returned.

Parameters:
key_len reference to an integer receiving the key length in bytes
Returns:
pointer to the array of unsigned 8bit integers holding the key.

Definition at line 136 of file key.h.

References key, and KEYLENGTH.

uint32_t YAPET::Key::ivec_size (  )  const [inline]

Returns the length of the initialization vector in bytes.

Returns:
the size of the initialization vector in bytes.

Definition at line 202 of file key.h.

References IVECLENGTH.

Referenced by YAPET::Crypt::decrypt(), YAPET::Crypt::encrypt(), and operator==().

YAPET::Key::operator const uint8_t * (  )  const [inline]

Returns the pointer to the key.

Definition at line 243 of file key.h.

References key.

YAPET::Key::operator uint8_t * (  )  [inline]

Returns the pointer to the key.

Definition at line 236 of file key.h.

References key.

bool YAPET::Key::operator!= ( const Key k  )  const [inline]

Definition at line 249 of file key.h.

References operator==().

const uint8_t* YAPET::Key::operator() (  )  const [inline]

Returns the key only. Please note that the key is not terminated by \0, so make sure you read only as many bytes as returned by size().

Returns:
pointer to the array of usigned 8bit integers holding the key.

Definition at line 229 of file key.h.

References key.

const uint8_t* YAPET::Key::operator() ( int &  key_len  )  const [inline]

Returns the key and its length. The key is not terminated by \0. So make sure you read only key_len bytes from the pointer returned.

Parameters:
key_len reference to an integer receiving the key length in bytes
Returns:
pointer to the array of unsigned 8bit integers holding the key.

Definition at line 217 of file key.h.

References getKey().

const Key & Key::operator= ( const Key k  ) 

Definition at line 245 of file key.cc.

References cleanup(), IVec, IVECLENGTH, key, and KEYLENGTH.

bool Key::operator== ( const Key k  )  const

Compares the key k provided for equality with this key.

Both, the key itself and the initialization vector are compared.

Parameters:
k reference to the key compared with this.
Returns:
true if both keys and initialization vectors are equal, false otherwise.

Definition at line 267 of file key.cc.

References IVec, ivec_size(), key, and size().

Referenced by operator!=().

uint32_t YAPET::Key::size (  )  const [inline]

Returns the key length in bytes

Returns:
key length in bytes.

Definition at line 192 of file key.h.

References KEYLENGTH.

Referenced by MainWindow::bottomRightWinContent(), YAPET::Crypt::decrypt(), YAPET::Crypt::encrypt(), and operator==().


Member Data Documentation

uint8_t YAPET::Key::IVec[IVECLENGTH] [private]

The initialization vector used for encryption and decryption.

Definition at line 112 of file key.h.

Referenced by cleanup(), getIVec(), Key(), operator=(), and operator==().

uint8_t YAPET::Key::key[KEYLENGTH] [private]

This is the key used to encrypt and decrypt data.

Definition at line 105 of file key.h.

Referenced by cleanup(), getKey(), Key(), operator const uint8_t *(), operator uint8_t *(), operator()(), operator=(), and operator==().


The documentation for this class was generated from the following files:

Generated on Thu Jun 11 19:13:05 2009 for YAPET by  doxygen 1.5.8