mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 02:02:42 +02:00
Merge bitcoin/bitcoin#28060: util: Teach AutoFile how to XOR
fa633aa690streams: Teach AutoFile how to XOR (MarcoFalke)000019e158Add AutoFile::detail_fread member function (MarcoFalke)fa7724bc9drefactor: Modernize AutoFile (MarcoFalke)fa8d227d58doc: Remove comments that just repeat what the code does (MarcoFalke)fafe2ca0cerefactor: Remove redundant file check from AutoFile shift operators (MarcoFalke)9999a49b32Extract util::Xor, Add key_offset option, Add bench (MarcoFalke) Pull request description: This allows `AutoFile` to roll an XOR pattern while reading or writing to the underlying file. This is needed for https://github.com/bitcoin/bitcoin/pull/28052, but can also be used in any other place. Also, there are tests, so I've split this up from the larger pull to make review easier, hopefully. ACKs for top commit: Crypt-iQ: crACKfa633aawillcl-ark: Lightly tested ACKfa633aa690jamesob: reACKfa633aa690([`jamesob/ackr/28060.4.MarcoFalke.util_add_xorfile`](https://github.com/jamesob/bitcoin/tree/ackr/28060.4.MarcoFalke.util_add_xorfile)) Tree-SHA512: 6d66cad0a089a096d3f95e4f2b28bce80b349d4b76f53d09dc9a0bea4fc1b7c0652724469c37971ba27728c7d46398a4c1d289c252af4c0f83bb2fcbc6f8e90b
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <bench/nanobench.h>
|
||||
#include <bench/nanobench.h> // IWYU pragma: export
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
|
||||
24
src/bench/xor.cpp
Normal file
24
src/bench/xor.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or https://opensource.org/license/mit/.
|
||||
|
||||
#include <bench/bench.h>
|
||||
|
||||
#include <random.h>
|
||||
#include <streams.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
static void Xor(benchmark::Bench& bench)
|
||||
{
|
||||
FastRandomContext frc{/*fDeterministic=*/true};
|
||||
auto data{frc.randbytes<std::byte>(1024)};
|
||||
auto key{frc.randbytes<std::byte>(31)};
|
||||
|
||||
bench.batch(data.size()).unit("byte").run([&] {
|
||||
util::Xor(data, key);
|
||||
});
|
||||
}
|
||||
|
||||
BENCHMARK(Xor, benchmark::PriorityLevel::HIGH);
|
||||
Reference in New Issue
Block a user