summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-09-25 13:50:08 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-12-16 00:56:19 +0000
commitef2d49f1592dc2efff798e2370897edc0bb7d113 (patch)
tree6df4fc6ca41a6a60b2b01a7857cd4045b02cd53e
parent2f58f553968059707016f709711a74dc93b3d0e1 (diff)
downloadchrome-ec-ef2d49f1592dc2efff798e2370897edc0bb7d113.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> (cherry picked from commit aeea9974b207d8bde78d2e78e71bb7dd3d708a8c) Reviewed-on: https://chromium-review.googlesource.com/828417
-rw-r--r--chip/g/dcrypto/bn.c26
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;