mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Merge bitcoin/bitcoin#33039: refactor,test: follow-ups to multi-byte block obfuscation
86e3a0a8cbrefactor: standardize obfuscation memory alignment (Lőrinc)13f00345c0refactor: write `Obfuscation` object when new key is generated in dbwrapper (Lőrinc)e5b1b7c557refactor: rename `OBFUSCATION_KEY_KEY` (Lőrinc)298bf95105refactor: simplify `Obfuscation::HexKey` (Lőrinc)2dea045425test: make `obfuscation_serialize` more thorough (Lőrinc)a17d8202c3test: merge xor_roundtrip_random_chunks and xor_bytes_reference (Lőrinc) Pull request description: Follow up for https://github.com/bitcoin/bitcoin/pull/31144 Applied the remaining comments in separate commits - except for the last one where I could group them. Please see the commit messages for more context. ACKs for top commit: achow101: ACK86e3a0a8cbryanofsky: Code review ACK86e3a0a8cb, just tweaking key write assert as suggested hodlinator: ACK86e3a0a8cbTree-SHA512: 967510a141fbb57bf9d088d92b554cf2fffc2f6aa0eab756cbae3230f53e9b04ceebcc6fea5f3383c01ad41985ecde5b5686c64a771ca9deae3497b9b88c1c8b
This commit is contained in:
@@ -249,11 +249,12 @@ CDBWrapper::CDBWrapper(const DBParams& params)
|
||||
LogInfo("Finished database compaction of %s", fs::PathToString(params.path));
|
||||
}
|
||||
|
||||
assert(!m_obfuscation); // Needed for unobfuscated Read()/Write() below
|
||||
if (!Read(OBFUSCATION_KEY_KEY, m_obfuscation) && params.obfuscate && IsEmpty()) {
|
||||
// Generate, write and read back the new obfuscation key, making sure we don't obfuscate the key itself
|
||||
Write(OBFUSCATION_KEY_KEY, FastRandomContext{}.randbytes(Obfuscation::KEY_SIZE));
|
||||
Read(OBFUSCATION_KEY_KEY, m_obfuscation);
|
||||
if (!Read(OBFUSCATION_KEY, m_obfuscation) && params.obfuscate && IsEmpty()) {
|
||||
// Generate and write the new obfuscation key.
|
||||
const Obfuscation obfuscation{FastRandomContext{}.randbytes<Obfuscation::KEY_SIZE>()};
|
||||
assert(!m_obfuscation); // Make sure the key is written without obfuscation.
|
||||
Write(OBFUSCATION_KEY, obfuscation);
|
||||
m_obfuscation = obfuscation;
|
||||
LogInfo("Wrote new obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
||||
}
|
||||
LogInfo("Using obfuscation key for %s: %s", fs::PathToString(params.path), m_obfuscation.HexKey());
|
||||
|
||||
Reference in New Issue
Block a user