Add const initializer to argon2::Block#427
Merged
tarcieri merged 1 commit intoRustCrypto:masterfrom Jun 22, 2023
Merged
Conversation
Merged
This file contains hidden or 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
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.
For
#![no_std]environments, adding the const initializer makes it possible to writePreviously, without a const initializer for
argon2::Block, doing the same would require code like the following:Unfortunately, the compiler is not able to optimize the initialization properly, resulting in an extra 1KB of space wasted on the stack, which becomes an issue in memory-constrained embedded systems. The following program is an illustration of this:
When compiled with
cargo build --release --target thumbv7em-none-eabi, the resulting assembly initializes eachargon2::Blockon the stack and themmemcpys it into the global array:Thus, adding a const initializer for
argon2::Blockmakes using the crate in embedded environments easier, as well as saving stack space. The particular project that I extracted this code from was very tight on memory space, almost needing to account for every single available RAM byte that the particular microcontroller we were using had available.The
argon2crate was the only instance I found of a customargon2::Blocktype, but if there are others, I think they should all get a const initializer as well.