Skip to content
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

blake2: add Cargo feature to optimize for code size. #440

Merged
merged 1 commit into from Dec 16, 2022

Conversation

Dirbaio
Copy link
Contributor

@Dirbaio Dirbaio commented Dec 9, 2022

The implementation uses some inline(always) to force inline the round and quarter_round functions for performance. This PR adds an opt-in Cargo feature to disable them, to allow optimizing for size instead.

Building for thumbv6m-none-eabi:

  • size_opt disabled: 5772 bytes
  • size_opt enabled: 2372 bytes

This saves 3.4kb of code size, which is 60%.

I'm trying to use blake2 on a microcontroller with 32kb of Flash memory (where the code is stored), so saving 3.4kb is quite substantial.

@@ -25,3 +25,4 @@ reset = [] # Enable reset functionality
simd = []
simd_opt = ["simd"]
simd_asm = ["simd_opt"]
size_opt = [] # Optimize for code size. Removes some `inline(always)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a new line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, done!

@newpavlov
Copy link
Member

Thank you! I will release it shortly.

@newpavlov newpavlov merged commit f8b2eab into RustCrypto:master Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants