-
Notifications
You must be signed in to change notification settings - Fork 95
New config.h option to make SHA-512 smaller #178
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
Conversation
Saves 356 bytes on sha512.o compiling for Cortex-M0+ with ARM-GCC Size measured with: arm-none-eabi-gcc -Wall -Wextra -Iinclude -Os -mcpu=cortex-m0plus -mthumb -c library/sha512.c arm-none-eabi-size sha512.o GCC version: arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]
Saves 108 bytes (measured as in previous commit).
Saves 1924 bytes (same measurement as before).
Patater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this. Will MBEDTLS_SHA512_SMALLER be tested in the full config tests in all.sh?
|
@Patater Thanks for your review! Yes, since the option is not excluded from |
Patater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
gilles-peskine-arm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I left suggestions for improvements.
| PUT_UINT64_BE(n, b, i); | ||
| } | ||
| #else | ||
| #define sha512_put_uint64_be PUT_UINT64_BE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we make it a function all the time and count on compilers to inline when compiling for performance?
|
|
||
| P( A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], W[i], K[i] ); | ||
|
|
||
| temp1 = A[7]; A[7] = A[6]; A[6] = A[5]; A[5] = A[4]; A[4] = A[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can save a few more bytes with
temp1 = A[7];
for( k = 1; k < 8; k++ )
A[k] = A[k - 1];
A[0] = temp1;
On the other hand, I tried removing the rotation of A and running
P( A[(80-i+0)%8], A[(80-i+1)%8], A[(80-i+2)%8], A[(80-i+3)%8], A[(80-i+4)%8], A[(80-i+5)%8], A[(80-i+6)%8], A[(80-i+7)%8],
W[i], K[i] );
but that has almost the same code size as your version. I wonder if there's more to gain there by tweaking P and its auxiliary macros to use temporaries for certain calculations.
|
CI on merge result is all passing. Jenkins failed to notify GitHub with the result. |
Add
MBEDTLS_SHA512_SMALLER, parallel toMBEDTLS_SHA256_SMALLER.Sizes, as measured with
arm-none-eabi-gcc -Wall -Wextra -Iinclude -Os -mcpu=cortex-m0plus -mthumb -c library/sha512.c && arm-none-eabi-size sha512.o:MBEDTLS_SHA512_SMALLER: 5691MBEDTLS_SHA512_SMALLER: 3411Speed impact on my laptop's i7, building with GCC -O2 and running
programs/test/benchmark sha512:Todo: