-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Large code size impact when using sha1 functions #6568
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
Comments
We already use BearSSL internal things in the Updater class (for signing), so I think a PR with your naive implementation would be fine. Just please make sure the API is the same as existing one to make it a transparent swap. |
dirkmueller
added a commit
to dirkmueller/Arduino
that referenced
this issue
Sep 30, 2019
The Hash library had its own copy of a loop-unrolled sha1 implementation adding a large code footprint for no good reason, as there are several sha1 implementations already in tree (one in NONOS-SDK as well as one in bearssl). Switching to the bearssl one is straightforward and removes about 3kb of code size overhead. Also cleanup some obvious inefficiencies (copy by value, string summing, no reservation causing repeated reallocations) in the implementation.
earlephilhower
added a commit
to earlephilhower/Arduino
that referenced
this issue
Sep 30, 2019
As @DirkMuller found out in esp8266#6568, there is a difference in code executed between `String str(nullptr)` and `String str("")`, but in the end the actual object is identical. It's a few bytes of code, but every little bit counts. Update the default `String()` constructor to use `nullptr` and not `""`. This will remove a constant literal load and the execution of the String::copy method and strlen().
devyte
pushed a commit
that referenced
this issue
Oct 1, 2019
As @DirkMuller found out in #6568, there is a difference in code executed between `String str(nullptr)` and `String str("")`, but in the end the actual object is identical. It's a few bytes of code, but every little bit counts. Update the default `String()` constructor to use `nullptr` and not `""`. This will remove a constant literal load and the execution of the String::copy method and strlen().
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic Infos
Platform
Problem Description
Using this code in a sketch:
causes the resulting firmware bin to grow by about 6kb of code size. this is predominantly due to the function SHA1Transform:
The root cause for that is ./libraries/Hash/src/sha1/sha1.c which is a large-machine optimized SHA1 implementation using unrolled loops and other optimisations for speed that are likely extremely unuseful for esp8266.
Interestingly in a typical sketch build there is also a 2nd sha1 implementation (at least) included from bearssl, which provides a similar api but with a much smaller footprint:
A very naive replacement of the lib/sha1 with the corresponding implementation from bearssl gives the expected footprint (code size) reduction, but it isn't clear to me if that is acceptable policy wise (dependency on bearssl in core hash lib). the impact in typical Arduino sketch builds using sha1() and https related functions is that we have (at least) two sha1 implemenations in the resulting binary, and one of them being very excessive in size.
The text was updated successfully, but these errors were encountered: