diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2017-09-25 13:50:08 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-09-26 16:14:06 -0700 |
commit | aeea9974b207d8bde78d2e78e71bb7dd3d708a8c (patch) | |
tree | 4fa95c0d51ed46c22567e3707c5aa84d6afc660f | |
parent | 0309b5581713ca4f9bd59dbca5c58bbda4acf676 (diff) | |
download | chrome-ec-aeea9974b207d8bde78d2e78e71bb7dd3d708a8c.tar.gz |
g: dcrypto: add debug function to print primes
When compilation is enabled, this function prints all prime numbers
generated using the PRIME_DELTAS array.
BRANCH=cr50
BUG=none
TEST=verified that prime numbers are printed out when running rsa_test.py
Change-Id: I37961aad146c4aeecca9a84550f313450e6c5853
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/683074
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | chip/g/dcrypto/bn.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/chip/g/dcrypto/bn.c b/chip/g/dcrypto/bn.c index 0b100402f5..f03db85c61 100644 --- a/chip/g/dcrypto/bn.c +++ b/chip/g/dcrypto/bn.c @@ -3,6 +3,10 @@ * found in the LICENSE file. */ +#ifdef PRINT_PRIMES +#include "console.h" +#endif + #include "dcrypto.h" #include "internal.h" @@ -1210,6 +1214,27 @@ static int bn_probable_prime(const struct LITE_BIGNUM *p) return 1; } +/* #define PRINT_PRIMES to enable printing predefined prime numbers' set. */ +static void print_primes(uint16_t prime) +{ +#ifdef PRINT_PRIMES + static uint16_t num_per_line; + static uint16_t max_printed; + + if (prime <= max_printed) + return; + + if (!(num_per_line++ % 8)) { + if (num_per_line == 1) + ccprintf("Prime numbers:"); + ccprintf("\n"); + cflush(); + } + max_printed = prime; + ccprintf(" %6d", prime); +#endif +} + int DCRYPTO_bn_generate_prime(struct LITE_BIGNUM *p) { int i; @@ -1232,6 +1257,7 @@ int DCRYPTO_bn_generate_prime(struct LITE_BIGNUM *p) uint16_t rem; prime += (PRIME_DELTAS[i] << 1); + print_primes(prime); rem = bn_mod_word16(p, prime); /* Skip marking odd offsets (i.e. even candidates). */ for (j = (rem == 0) ? 0 : prime - rem; |