diff options
author | James O'Beirne <james.obeirne@gmail.com> | 2015-09-07 15:22:23 -0700 |
---|---|---|
committer | James O'Beirne <james.obeirne@gmail.com> | 2015-10-06 07:46:10 -0700 |
commit | 42cb388167ef78f47a3a440eb651b6938c10f508 (patch) | |
tree | 5030db533bf8e2c8231b9df00865528a6f6b5706 /src/streams.h | |
parent | 3932ff50c563df19c14e9987f2297d9f99a299ac (diff) |
Add chainstate obfuscation to avoid spurious antivirus detection
Adds an `obfuscate` parameter to `CLevelDBWrapper` and makes use of it
for all new chainstate stores built via `CCoinsViewDB`. Also adds an
`Xor` method to `CDataStream`.
Thanks to @sipa @laanwj @pstratem @dexX7 @KyrosKrane @gmaxwell.
Diffstat (limited to 'src/streams.h')
-rw-r--r-- | src/streams.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/streams.h b/src/streams.h index fa1e18defe..8610e4d18e 100644 --- a/src/streams.h +++ b/src/streams.h @@ -296,6 +296,29 @@ public: data.insert(data.end(), begin(), end()); clear(); } + + /** + * XOR the contents of this stream with a certain key. + * + * @param[in] key The key used to XOR the data in this stream. + */ + void Xor(const std::vector<unsigned char>& key) + { + if (key.size() == 0) { + return; + } + + for (size_type i = 0, j = 0; i != size(); i++) { + vch[i] ^= key[j++]; + + // This potentially acts on very many bytes of data, so it's + // important that we calculate `j`, i.e. the `key` index in this + // way instead of doing a %, which would effectively be a division + // for each byte Xor'd -- much slower than need be. + if (j == key.size()) + j = 0; + } + } }; |