From a1c8d50e9b2bf61f18f49c3c8fb2659be62549cd Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Tue, 21 Feb 2017 09:10:19 +0100 Subject: [PATCH] Add option to adjust compiler optimization on RSA Using -O3 optimization level rather than -Os results in a large speed-up for a minor code size increase for the RSA code with our current GCC toolchain. Add the CONFIG_RSA_OPTIMIZED option to do it on platforms which are not too size-constrained. On cortex-M4 based STM32L432, I'm measuring a 37 to 40% speed increase (depending on CPU frequency) for a 200 bytes code size delta. Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=manual: benchmark RSA2048 with F4 exponent on STM32L432: -Os -O3 @16Mhz 185163 us --> 111942 us @80Mhz 39286 us --> 24582 us Change-Id: I8c2e4b757f037f4f645fb73ba0faaaa471b24896 Reviewed-on: https://chromium-review.googlesource.com/445218 Commit-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Nicolas Boichat --- common/build.mk | 5 +++++ include/config.h | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/common/build.mk b/common/build.mk index c3a9023fcb..6c13a9c4d0 100644 --- a/common/build.mk +++ b/common/build.mk @@ -127,3 +127,8 @@ else common-y+=test_util.o endif common-$(TEST_BUILD)+=sensor_common.o + +ifneq ($(CONFIG_RSA_OPTIMIZED),) +$(out)/RW/common/rsa.o: CFLAGS+=-O3 +$(out)/RO/common/rsa.o: CFLAGS+=-O3 +endif diff --git a/include/config.h b/include/config.h index 94ddba963c..19a6653161 100644 --- a/include/config.h +++ b/include/config.h @@ -1782,6 +1782,12 @@ /* Use RSA exponent 3 instead of F4 (65537) */ #undef CONFIG_RSA_EXPONENT_3 +/* + * Adjust the compiler optimization flags for the RSA code to get a speed-up + * at the expense of a small code size delta. + */ +#undef CONFIG_RSA_OPTIMIZED + /* * Verify the RW firmware using the RSA signature. * (for accessories without software sync)