-
Notifications
You must be signed in to change notification settings - Fork 572
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
Chore: BufferTransformer and Blowfish Refactor #4151
Draft
reneme
wants to merge
4
commits into
randombit:master
Choose a base branch
from
Rohde-Schwarz:rene/buffer_transformer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+513
−78
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reneme
force-pushed
the
rene/buffer_transformer
branch
2 times, most recently
from
June 27, 2024 07:15
4feb67d
to
87d4035
Compare
reneme
force-pushed
the
rene/buffer_transformer
branch
from
June 27, 2024 07:28
87d4035
to
7b3c762
Compare
As suggested, I also applied this to the AES-NI-128 encryption path to verify that See the resulting code here (clang 18): #4287 (comment) ... and the corresponding C++ code: BufferTransformer(std::span{in, blocks * BLOCK_SIZE}, std::span{out, blocks * BLOCK_SIZE})
.process_blocks_of<4 * BLOCK_SIZE, BLOCK_SIZE>(overloaded{
[&](std::span<const uint8_t, 4 * BLOCK_SIZE> in, std::span<uint8_t, 4 * BLOCK_SIZE> out) {
SIMD_4x32 B0 = SIMD_4x32::load_le(in.data() + 16 * 0);
SIMD_4x32 B1 = SIMD_4x32::load_le(in.data() + 16 * 1);
SIMD_4x32 B2 = SIMD_4x32::load_le(in.data() + 16 * 2);
SIMD_4x32 B3 = SIMD_4x32::load_le(in.data() + 16 * 3);
keyxor(K0, B0, B1, B2, B3);
aesenc(K1, B0, B1, B2, B3);
aesenc(K2, B0, B1, B2, B3);
aesenc(K3, B0, B1, B2, B3);
aesenc(K4, B0, B1, B2, B3);
aesenc(K5, B0, B1, B2, B3);
aesenc(K6, B0, B1, B2, B3);
aesenc(K7, B0, B1, B2, B3);
aesenc(K8, B0, B1, B2, B3);
aesenc(K9, B0, B1, B2, B3);
aesenclast(K10, B0, B1, B2, B3);
B0.store_le(out.data() + 16 * 0);
B1.store_le(out.data() + 16 * 1);
B2.store_le(out.data() + 16 * 2);
B3.store_le(out.data() + 16 * 3);
},
[&](std::span<const uint8_t, BLOCK_SIZE> in, std::span<uint8_t, BLOCK_SIZE> out) {
SIMD_4x32 B0 = SIMD_4x32::load_le(in.data());
B0 ^= K0;
aesenc(K1, B0);
aesenc(K2, B0);
aesenc(K3, B0);
aesenc(K4, B0);
aesenc(K5, B0);
aesenc(K6, B0);
aesenc(K7, B0);
aesenc(K8, B0);
aesenc(K9, B0);
aesenclast(K10, B0);
B0.store_le(out.data());
},
});
} |
reneme
force-pushed
the
rene/buffer_transformer
branch
from
August 5, 2024 12:48
7b3c762
to
c88455d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This picks up the work started in #3942 by proposing a
BufferTransformer
class; which is essentially an orchestrator forBufferSlicer
andBufferStuffer
. As mentioned yesterday, I added some template fanciness, to handle the "block processing" necessary for various block ciphers. As suggested previously, this uses Blowfish to demonstrate the functionality (+ spanifying the blowfish implementation).@randombit Is the
process_blocks_of<>
implementation in line with what you had in mind previously:Here's the idea of
BufferTransformer::process_blocks_of
, where the multi-block loop handling and buffer management is entirely abstracted. Also, as an additional goodie, we now have explicit compile-time knowledge of the blocked data length inside the processing lambdas. Whether the compiler uses this or not has to be seen. FWIW: I don't see a difference in the performance of Blowfish on my Mac.No hard feelings if that doesn't make it into 3.5.0 at all. I just nerd-sniped myself yesterday and wanted to sketch this out. And frankly, I think the
BufferTransformer
implementation is quite concise. 😄