diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-03-03 10:12:07 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-28 22:46:28 -0700 |
commit | 49ff62bf0be5cfc88e092f987d77c18a0b21390a (patch) | |
tree | 4f7fc10f29d02422bcdba81d9964de1bf6d91eb8 /include/util.h | |
parent | 6e364d59c1ae658876b8a0e58a38edd81233655d (diff) | |
download | chrome-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 'include/util.h')
-rw-r--r-- | include/util.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h index 453ff8c739..2670d4e5ad 100644 --- a/include/util.h +++ b/include/util.h @@ -182,4 +182,22 @@ static inline int cond_went_true(cond_t *c) { return cond_went(c, 1); } int parse_offset_size(int argc, char **argv, int shift, int *offset, int *size); +#ifdef CONFIG_ASSEMBLY_MULA32 +/* + * Compute (a*b)+c, where a, b, c are 32-bit integers, and the result is + * 64-bit long. + */ +uint64_t mula32(uint32_t a, uint32_t b, uint32_t c); +#else +static inline uint64_t mula32(uint32_t a, uint32_t b, uint32_t c) +{ + uint64_t ret = a; + + ret *= b; + ret += c; + + return ret; +} +#endif + #endif /* __CROS_EC_UTIL_H */ |