#include <key.h>
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 Key & | operator= (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. |
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.
anonymous enum [private] |
Key::Key | ( | const char * | password | ) | throw (YAPETException) |
Key::Key | ( | const Key & | k | ) |
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()
.
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.
ivec_len | a reference to an integer receiving the length of 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()
.
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.
key_len | reference to an integer receiving the key length in bytes |
uint32_t YAPET::Key::ivec_size | ( | ) | const [inline] |
Returns the length 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] |
YAPET::Key::operator uint8_t * | ( | ) | [inline] |
bool YAPET::Key::operator!= | ( | const Key & | k | ) | const [inline] |
const uint8_t* YAPET::Key::operator() | ( | ) | const [inline] |
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.
key_len | reference to an integer receiving the key length in bytes |
Definition at line 217 of file key.h.
References getKey().
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.
k | reference to the key compared with this. |
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
Definition at line 192 of file key.h.
References KEYLENGTH.
Referenced by MainWindow::bottomRightWinContent(), YAPET::Crypt::decrypt(), YAPET::Crypt::encrypt(), and operator==().
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==().