Add const initializer to argon2::Block #427
Merged
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::Block
on the stack and themmemcpy
s it into the global array:Thus, adding a const initializer for
argon2::Block
makes 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
argon2
crate was the only instance I found of a customargon2::Block
type, but if there are others, I think they should all get a const initializer as well.