-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[std::span] {load,store}_{le,be} #3707
Conversation
d30a10c
to
a5b2609
Compare
340e1c9
to
c71ad68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this looks like a nice improvement, main concern would be if there are any performance implications. I would think not for the case where endian is known at compile time so we can make use of memcpy, and the targets where it's not known (or anyway assumed) are all relatively obscure, but I'd like to not introduce a regression if we don't have to.
c71ad68
to
b505e75
Compare
b505e75
to
3efecc4
Compare
Rebased after #3711 fixed the CI build. |
a64e90b
to
bd1a6df
Compare
bd1a6df
to
df9deee
Compare
Lets postpone this for a moment. I'm hoping that the iOS/Android update will bring more tools to make this easier. |
I'm going to either update the emscripten build (#3720) or just disable the emscripten CI build, at which point we should be able to rely on having most of C++20. [*] Outside of |
df9deee
to
483b8aa
Compare
uint8_t final_block[GCM_BS]; | ||
store_be<uint64_t>(final_block, 8 * ad_len, 8 * text_len); | ||
ghash_update(hash, {final_block, GCM_BS}); | ||
std::array<uint8_t, GCM_BS> final_block; | ||
|
||
const uint64_t ad_bits = 8 * ad_len; | ||
const uint64_t text_bits = 8 * text_len; | ||
store_be(final_block, ad_bits, text_bits); | ||
ghash_update(hash, final_block); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch was needed to explicitly convert size_t
to uint64_t
on 32-bit platforms.
a222459
to
e2c2825
Compare
This will need a rebase. But let's review/merge #3715 first and get this done after. |
I'll review this PR in the following days! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I'm looking forward to using these new interfaces! This will beautify many places, where load/store is used 😃
662db92
to
64b4228
Compare
These overloads auto-detect their required return type at compile-time given the input parameter type.
64b4228
to
b4c057e
Compare
@FAlbertDev @randombit I rebased to master, and addressed the pending review comments (except the docstring remarks). Request for Comment: Type inferring overloads for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I like the static return type deduction! We could discuss if we still want to add load/store members to the BufferSlicer and BufferStuffer. For now, however, I think this PR is ready to merge.
Co-authored-by: Fabian Albert <[email protected]>
Thanks for the thorough review! @randombit no particular rush with this, but I'd love to have it in (after discussing #3707 (comment)) to get Frodo and LMS adapted to this. Kyber and Dilithium will follow. |
Change itself looks fine, and a nice cleanup overall. I do see a minor but persistent performance regression with Blowfish (about .2 cycles/byte slower) but for whatever reason that's the only algorithm I can find that seems slower, so not a problem. |
🎉 |
Pull Request Dependencies
Range-based mem_ops #3715Description
This has two objectives:
The lack of this has been annoying me for some time now. Using ranges facilitates maximum usage convenience while enabling opportunistic compile-time buffer size checks when the passed range has static length information (read:
std::array
orstd::span<T, 42>
). Otherwise runtime checks will be performed (BOTAN_ARG_CHECK
).... by letting the compiler generate most of the generic code as
constexpr
. I didn't see any slow-downs (in the runtime of the test suite) after applying this.Here's a godbolt (of a somewhat stripped-down version) to play around with that, if needed: https://godbolt.org/z/sxjhnbePo
Currently, this includes legacy (pointer-based) overloads of the existing helpers. Those just assert that the passed in pointers are big enough and wrap them into properly sized
std::span
s to forward the calls. In an ideal world we'd need to go through the code base and replace all those calls with statically checkable invocations.