|
libkeepass 0.2.0
KeePass key database importer/exporter library
|
Manages database encryption keys for KDB and KDBX formats. More...
#include <key.hh>
Public Types | |
| enum class | SubKeyResolution { kHashSubKeys , kHashSubKeysOnlyIfCompositeKey } |
| enum class | Kdf { kAes , kArgon2d , kArgon2id } |
Public Member Functions | |
| Key ()=default | |
| Default constructor. Creates an empty key with no password or key file. | |
| Key (const Key &other) | |
| Copy-constructs, allocating wiped copies of all sub keys. | |
| Key & | operator= (const Key &other) |
| Copy-assigns, allocating wiped copies of all sub keys. | |
| Key (const std::string &password) | |
| Constructs a key with the given password. | |
| Key (const std::string &password, const std::string &keyfile) | |
| Constructs a composite key from a password and a key file. | |
| Key (const std::vector< uint8_t > &transformed_key) | |
| Constructs a key from a pre-derived transformed master key. | |
| void | SetPassword (const std::string &password) |
| Sets the password used to derive the encryption key. | |
| void | SetKeyFile (const std::string &path) |
| Loads a key file and derives the key file component from it. | |
| void | SetKeyFile (std::istream &src) |
| Loads a key file from an in-memory stream. | |
| void | SetKeyFileData (const uint8_t *data, std::size_t size) |
| Loads a key file from an in-memory byte range. | |
| SecureBuffer< 32 > | Transform (const SecureBuffer< 32 > &seed, uint64_t rounds, SubKeyResolution resolution) const |
| Derives the composite key using AES-KDF for KDBX 3 databases. | |
| SecureBuffer< 32 > | TransformArgon2 (Kdf kdf, const SecureBytes &salt, uint64_t iterations, uint64_t memory_bytes, uint32_t parallelism, uint32_t argon2_version, SubKeyResolution resolution) const |
| Derives the composite key using Argon2 for KDBX 4 databases. | |
Static Public Member Functions | |
| static Key | FromBytes (const std::string &password, const std::vector< uint8_t > &keyfile) |
| Creates a composite key from a password and an in-memory key file. | |
| static Key | FromStream (const std::string &password, std::istream &keyfile) |
| Creates a composite key from a password and a key-file stream. | |
Static Public Attributes | |
| static constexpr std::size_t | kMaxKeyFileBytes = 1024 * 1024 |
| Maximum size of a key file accepted by the parser. | |
Manages database encryption keys for KDB and KDBX formats.
Supports password-based keys, key file-based keys, and composite keys (password + key file combined). Provides key derivation via AES-KDF or Argon2 for KDBX 4 databases.
|
strong |
Key derivation functions supported for KDBX 4 databases.
| Enumerator | |
|---|---|
| kAes | AES-KDF (repeated AES-ECB, used by KDBX 3). |
| kArgon2d | Argon2d. |
| kArgon2id | Argon2id. |
Strategies for how to resolve sub keys before applying the transformation.
|
explicit |
Constructs a key with the given password.
| password | The password string used to derive the encryption key. |
Constructs a composite key from a password and a key file.
| password | The password string used to derive the password part. |
| keyfile | Path to the key file used to derive the key file part. |
Constructs a key from a pre-derived transformed master key.
The supplied 32-byte key is used directly as the result of any key derivation, bypassing the password and key file processing. This is useful for re-opening databases with an already computed transformed key.
| transformed_key | The 32-byte pre-derived transformed key. |
|
static |
Creates a composite key from a password and an in-memory key file.
| password | Password part of the composite key. |
| keyfile | Raw key file contents. |
Creates a composite key from a password and a key-file stream.
| password | Password part of the composite key. |
| keyfile | Stream containing the key file. |
Loads a key file and derives the key file component from it.
The file may be an XML v1/v2 key file, a 64-character hexadecimal key or 32 raw bytes. Files larger than kMaxKeyFileBytes are rejected.
| path | Path to the key file on disk. |
| void keepass::Key::SetKeyFile | ( | std::istream & | src | ) |
Loads a key file from an in-memory stream.
The stream is consumed from its current position. At most kMaxKeyFileBytes are read; larger inputs are rejected.
| src | Stream containing the key file. |
Loads a key file from an in-memory byte range.
| data | Pointer to the key file contents. |
| size | Number of bytes in data. |
Sets the password used to derive the encryption key.
| password | The password string used to derive the encryption key. |
| SecureBuffer< 32 > keepass::Key::Transform | ( | const SecureBuffer< 32 > & | seed, |
| uint64_t | rounds, | ||
| SubKeyResolution | resolution | ||
| ) | const |
Derives the composite key using AES-KDF for KDBX 3 databases.
| seed | The key derivation seed (master seed). |
| rounds | Number of AES-KDF transformation rounds. |
| resolution | Strategy for resolving sub keys before transformation. |
| SecureBuffer< 32 > keepass::Key::TransformArgon2 | ( | Kdf | kdf, |
| const SecureBytes & | salt, | ||
| uint64_t | iterations, | ||
| uint64_t | memory_bytes, | ||
| uint32_t | parallelism, | ||
| uint32_t | argon2_version, | ||
| SubKeyResolution | resolution | ||
| ) | const |
Derives the composite key using Argon2 for KDBX 4 databases.
| kdf | The Argon2 variant to use (Argon2d or Argon2id). |
| salt | The salt for the key derivation. |
| iterations | Number of Argon2 iterations (time cost). |
| memory_bytes | Memory cost in bytes for Argon2. |
| parallelism | Degree of parallelism for Argon2. |
| argon2_version | Argon2 algorithm version (0x10 for 1.0, 0x13 for 1.3). |
| resolution | Strategy for resolving sub keys before transformation. |
|
staticconstexpr |
Maximum size of a key file accepted by the parser.
Genuine KeePass key files are only a few hundred bytes (32 raw or base64-encoded bytes plus a small XML wrapper). The upper bound keeps a hostile file from making the parser buffer an unbounded amount of data.