sipa
commented at 6:34 pm on July 18, 2023:
member
This modernizes the ChaCha20 and ChaCha20Aligned interfaces to be Span<std::byte> based, and other improvements.
Modifies all functions and constructors of ChaCha20 and ChaCha20Aligned to be Span<std::byte> based (aligning them with FSChaCha20, AEADChaCha20Poly1305, and FSChaCha20Poly1305)
Remove default constructors, to make sure all call sites provide a key (suggested in #26153 (review))
Wipe key material on rekey for security (suggested in #26153 (review))
Use HexStr on byte vectors in tests (suggested in #27993 (review))
Support std::byte vectors in ConsumeRandomLengthByteVector and ConsumeFixedLengthByteVector, and use it (suggested in #27993 (review))
And a few more.
While related, I don’t see this as a necessary for BIP324.
DrahtBot
commented at 6:34 pm on July 18, 2023:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviews
See the guideline for information on the review process.
0random.cpp:668:44: error: non-type template argument is not a constant expression
1static constexpr std::array<std::byte, rng.KEYLEN> ZERO{};
2^~~~~~~~~~3random.cpp:668:44: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
41 error generated.
in
src/test/fuzz/crypto_chacha20.cpp:19
in
b1faef7cf4outdated
19- if (fuzzed_data_provider.ConsumeBool()) {
20- const std::vector<unsigned char> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, 32);
21- chacha20 = ChaCha20{MakeByteSpan(key)};
22- }
23+ // Just for compatibility with old seeds (it used to test the default constructor which used zero key)
24+ if (!fuzzed_data_provider.ConsumeBool()) return;
Any reason to do this? Fuzz inputs may already invalidate for any code change and maintaining compat for some code changes seems inconsistent, will bloat the fuzz code, and cause maintenance overhead in the future.
Would be good to either remove this, or if you actually want to maintain compat use a ternary operator:
in
src/test/fuzz/crypto_diff_fuzz_chacha20.cpp:275
in
b1faef7cf4outdated
280- } else {
281- // The default ChaCha20 constructor is equivalent to using the all-0 key.
282- ECRYPT_keysetup(&ctx, ZEROKEY, 256, 0);
283- }
284+ // Just for compatibility with old seeds (it used to test the default constructor which used zero key)
285+ if (!fuzzed_data_provider.ConsumeBool()) return;
2ff930de1c7f4683d0a7a72970683e21bf20ba73: My preference would be to instead base this on a new commit that just does a input -> m_input (“scripted-diff”) rename
unrelated: In C++20, we’ll probably have to provide overloads for operator==(std::span, std::span), because equality checks are only defined in the std lib for containers that store memory, it seems.
Just brainstorming at this point, but perhaps we don’t want to actually add an overload for an STL class operator. Perhaps std::ranges::equal can be used instead.
maflcko approved
maflcko
commented at 11:30 am on August 8, 2023:
member
DrahtBot added the label
Needs rebase
on Aug 10, 2023
sipa force-pushed
on Aug 14, 2023
DrahtBot removed the label
Needs rebase
on Aug 14, 2023
sipa
commented at 2:28 am on August 14, 2023:
member
Rebased after merge of #28008, and addresses feedback. I’ve dropped the Crypt -> Encrypt / Decrypt change as I felt the duplication that resulted wasn’t worth it anymore.
DrahtBot added the label
CI failed
on Aug 14, 2023
sipa force-pushed
on Aug 14, 2023
DrahtBot removed the label
CI failed
on Aug 14, 2023
fanquake
commented at 11:55 am on August 14, 2023:
member
Some changes here are also in #28008, but either or both can go in.
@sipa could you update the PR dscription in regards to this, now that #28008 has been merged.
cc @stratospher you might be interested in reviewing here?
in
src/crypto/chacha20.h:116
in
bc0a7145eboutdated
134+ /** en/deciphers the message <in_bytes> and write the result into <out_bytes>
135+ *
136+ * The size of in_bytes and out_bytes must be equal.
137 */
138- void Crypt(const unsigned char* input, unsigned char* output, size_t bytes);
139+ void Crypt(Span<const std::byte> in_bytes, Span<std::byte> out_output) noexcept;
stratospher
commented at 1:02 pm on August 14, 2023:
Potential follow-up nit: there might be some more instances where using BOOST_CHECK_EQUAL over BOOST_CHECK could make sense, see git grep "BOOST_CHECK(.*==" ./src/test/crypto_tests.cpp.
fanquake
commented at 2:33 pm on August 17, 2023:
member
@sipa when you get a chance to respond to review comments here, we can decide to either merge as-is, and address in a followup, or touch up here.
maflcko
commented at 2:44 pm on August 17, 2023:
member
I think they should either be fixed up here or not at all. I don’t think it makes sense to create a follow-up to a follow-up.
sipa
commented at 2:45 pm on August 17, 2023:
member
I will address them.
crypto: refactor ChaCha20 classes to use Span<std::byte> interface3da636e08b
random: simplify FastRandomContext::randbytes using fillrand44c11769a8
crypto: require key on ChaCha20 initialization7d1cd93234
fuzz: support std::byte in Consume{Fixed,Variable}LengthByteVectorbdcbc8594c
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2025-04-02 03:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me