summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2017-03-03 10:12:07 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-05-28 22:46:28 -0700
commit49ff62bf0be5cfc88e092f987d77c18a0b21390a (patch)
tree4f7fc10f29d02422bcdba81d9964de1bf6d91eb8 /test
parent6e364d59c1ae658876b8a0e58a38edd81233655d (diff)
downloadchrome-ec-49ff62bf0be5cfc88e092f987d77c18a0b21390a.tar.gz
rsa: Optimization of multiplications for Cortex-M0
We multiply 2 32-bit numbers (and not 64-bit numbers), and then add another 32-bit number, which makes it possible to optimize the assembly and save a few instructions. With -O3, 3072-bit exponent, lower verification time from 122 ms to 104 ms on STM32F072 @48Mhz. Optimized mac function from Dmitry Grinberg <dmitrygr@google.com>. BRANCH=poppy BUG=b:35647963 BUG=b:77608104 TEST=On staff, flash, verification successful TEST=make test-rsa, make test-rsa3 TEST=Flash test-utils and test-rsa to hammer => pass Change-Id: I584c54c631a3f59f691849a279b308e8d4b4b22d Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/449024 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/utils.c b/test/utils.c
index b3ed2fc9dc..7acf238c14 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -12,6 +12,7 @@
#include "test_util.h"
#include "timer.h"
#include "util.h"
+#include "watchdog.h"
static int test_memmove(void)
{
@@ -356,6 +357,31 @@ static int test_cond_t(void)
return EC_SUCCESS;
}
+static int test_mula32(void)
+{
+ uint64_t r = 0x0;
+ uint32_t b = 0x1;
+ uint32_t c = 0x1;
+ uint32_t i;
+ timestamp_t t0, t1;
+
+ t0 = get_time();
+ for (i = 0; i < 5000000; i++) {
+ r = mula32(b, c, r + (r >> 32));
+ b = (b << 13) ^ (b >> 2) ^ i;
+ c = (c << 16) ^ (c >> 7) ^ i;
+ watchdog_reload();
+ }
+ t1 = get_time();
+
+ ccprintf("After %d iterations, r=%08x%08x (time: %d)\n", i,
+ (uint32_t)(r >> 32), (uint32_t)r, t1.le.lo-t0.le.lo);
+ TEST_ASSERT(r == 0x9df59b9fb0ab9d96L);
+
+ /* well okay then */
+ return EC_SUCCESS;
+}
+
void run_test(void)
{
test_reset();
@@ -371,6 +397,7 @@ void run_test(void)
RUN_TEST(test_shared_mem);
RUN_TEST(test_scratchpad);
RUN_TEST(test_cond_t);
+ RUN_TEST(test_mula32);
test_print_result();
}