libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
Extension points: codecs, ciphers and KDFs

libkeepass exposes three registries so format/crypto extensions do not have to modify the unified API. All registries are process-wide and use a function-local static for construction, so registration order across translation units does not matter.

Format codecs (<tt>detail::FormatCodecRegistry</tt>)

A codec imports/exports one dialect and returns/accepts the object model:

class MyCodec : public keepass::detail::FormatCodec {
std::unique_ptr<keepass::Database> Import(std::istream&, const keepass::Key&) override;
void Export(std::ostream&, const keepass::Database&, const keepass::Key&) override;
};
return std::make_unique<MyCodec>();
});
Represents a KeePass (KDB/KDBX) database.
Definition database.hh:74
Manages database encryption keys for KDB and KDBX formats.
Definition key.hh:45
void Register(int format, FormatCodecFactory factory)
Registers/overwrites the factory for a numeric format id.
static FormatCodecRegistry & Instance()
Returns the process-wide registry.
Imports/exports one database dialect.
Definition format_codec.hh:66
virtual void Export(std::ostream &dst, const Database &db, const Key &key)=0
Exports db to dst using key.
virtual std::unique_ptr< Database > Import(std::istream &src, const Key &key)=0
Imports a database from src using key.
Registrable format codecs used by the unified KeePass API.
Options that influence codec construction.
Definition format_codec.hh:50

The numeric ids for the built-ins are detail::kFormatKdb (1), detail::kFormatKdbx3 (2) and detail::kFormatKdbx4 (3). A codec registered for a new id can be used by extending the public KeePass::Format enum (or by calling the registry directly).

Block ciphers (<tt>CipherRegistry</tt>)

libkeepass/cipher_registry.hh maps a Database::Cipher id to a factory for a 16-byte block cipher. The core uses it for KDB and KDBX 3/4 AES/Twofish payloads. ChaCha20 is a stream cipher and remains a dedicated code path because its framing has no block padding.

keepass::Database::Cipher::kAes,
[](const uint8_t* key, const std::array<uint8_t, 16>& iv) {
return std::unique_ptr<keepass::Cipher<16>>(new MyAes(key, iv));
});
static CipherRegistry & Instance()
Returns the process-wide registry.
void Register(Database::Cipher cipher, Factory factory)
Registers/overwrites the factory for a payload cipher id.

KDFs (<tt>KdfRegistry</tt>)

libkeepass/kdf_registry.hh maps a Database::Kdf id to a transform factory. KdbxKdf::Transform (and therefore every KDBX import/export) resolves through it. Built-ins are AES-KDF, Argon2d and Argon2id. A new KDF still needs its parameter dictionary UUID/parse/serialize path in KdbxKdf; the registry isolates the expensive transform itself.

Compatibility

The built-in KDBX export chooses KDBX 3 (and therefore AES-KDF) whenever the database uses AES + AES-KDF. Selecting KDBX 4 explicitly is required for ChaCha20, Argon2 or KDBX-4-only features (KeePass::SetFormat).