libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
keepass::RandomObfuscator Class Reference

#include <random.hh>

Public Types

enum class  Type { kSalsa20 , kChaCha20 }
 

Public Member Functions

 RandomObfuscator (const std::array< uint8_t, 32 > &key, const std::array< uint8_t, 8 > &init_vec)
 Constructs a random stream cipher from a raw key and initialization vector.
 
 RandomObfuscator (Type type, const std::array< uint8_t, 32 > &stream_key)
 
 RandomObfuscator (Type type, const std::vector< uint8_t > &stream_key)
 
 ~RandomObfuscator ()
 Wipes the buffered keystream and destroys the underlying ciphers.
 
std::vector< uint8_t > Process (const std::vector< uint8_t > &data)
 Obfuscates or deobfuscates a byte vector using the random stream.
 
std::string Process (const std::string &data)
 Obfuscates or deobfuscates a string using the random stream.
 
secure_string Process (const secure_string &data)
 Obfuscates or deobfuscates a sensitive string using the random stream.
 

Detailed Description

Obfuscates binary data by xorring each byte with psuedo random data generated by a Salsa20 or ChaCha20 stream cipher.

Member Enumeration Documentation

◆ Type

Inner random stream ciphers supported by KDBX 4.

Enumerator
kSalsa20 

Salsa20 stream cipher (KDBX 3 and 4).

kChaCha20 

ChaCha20 stream cipher (KDBX 4).

Constructor & Destructor Documentation

◆ RandomObfuscator() [1/3]

keepass::RandomObfuscator::RandomObfuscator ( const std::array< uint8_t, 32 > &  key,
const std::array< uint8_t, 8 > &  init_vec 
)

Constructs a random stream cipher from a raw key and initialization vector.

Parameters
keyThe 32-byte key for the stream cipher.
init_vecThe 8-byte initialization vector.

◆ RandomObfuscator() [2/3]

keepass::RandomObfuscator::RandomObfuscator ( Type  type,
const std::array< uint8_t, 32 > &  stream_key 
)

Constructs a random stream cipher from the raw inner random stream key using the key transformation rule of the KDBX 4 format. For Salsa20 the key is hashed with SHA-256 and used with a fixed IV. For ChaCha20 the key is hashed with SHA-512 and split into a 32 byte key and 12 byte IV.

◆ RandomObfuscator() [3/3]

keepass::RandomObfuscator::RandomObfuscator ( Type  type,
const std::vector< uint8_t > &  stream_key 
)

Constructs a random stream cipher from the raw inner random stream key of KDBX 4, which may be 32 or 64 bytes depending on the writer.

Member Function Documentation

◆ Process() [1/3]

secure_string keepass::RandomObfuscator::Process ( const secure_string &  data)

Obfuscates or deobfuscates a sensitive string using the random stream.

Parameters
dataThe sensitive string data to process.
Returns
The processed string, stored in wiped memory.

◆ Process() [2/3]

std::string keepass::RandomObfuscator::Process ( const std::string &  data)

Obfuscates or deobfuscates a string using the random stream.

Parameters
dataThe string data to process.
Returns
The processed string.

◆ Process() [3/3]

std::vector< uint8_t > keepass::RandomObfuscator::Process ( const std::vector< uint8_t > &  data)

Obfuscates or deobfuscates a byte vector using the random stream.

Parameters
dataThe data to process (xor with the random stream).
Returns
The processed data.

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