[Cryptech-Commits] [sw/libhal] 43/58: Add temporary workaround to let us use software ModExp when we're testing other code and don't want to wait for the as-yet-unoptimized FPGA ModExp core.

git at cryptech.is git at cryptech.is
Tue Jul 7 18:25:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch master
in repository sw/libhal.

commit 79d3c33ee5f6fd0cfb24af68357e084e4f1fded0
Author: Rob Austein <sra at hactrn.net>
Date:   Fri Jun 19 11:50:31 2015 -0400

    Add temporary workaround to let us use software ModExp when we're
    testing other code and don't want to wait for the as-yet-unoptimized
    FPGA ModExp core.
---
 rsa.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/rsa.c b/rsa.c
index cda0f7f..85ac8ee 100644
--- a/rsa.c
+++ b/rsa.c
@@ -49,6 +49,15 @@
 #include "cryptech.h"
 
 /*
+ * Whether to use ModExp core.  It works, but at the moment it's so
+ * slow that a full test run can take more than an hour.
+ */
+
+#ifndef HAL_RSA_USE_MODEXP
+#define HAL_RSA_USE_MODEXP 1
+#endif
+
+/*
  * Use "Tom's Fast Math" library for our bignum implementation.  This
  * particular implementation has a couple of nice features:
  *
@@ -154,6 +163,8 @@ static hal_error_t unpack_fp(fp_int *bn, uint8_t *buffer, const size_t length)
   return err;
 }
 
+#if HAL_RSA_USE_MODEXP
+
 /*
  * Unwrap bignums into byte arrays, feeds them into hal_modexp(), and
  * wrap result back up as a bignum.
@@ -206,6 +217,24 @@ int fp_exptmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
   return modexp(a, b, c, d) == HAL_OK ? FP_OKAY : FP_VAL;
 }
 
+#else /* HAL_RSA_USE_MODEXP */
+
+/*
+ * Workaround to let us use TFM's software implementation of modular
+ * exponentiation when we want to test other things and don't want to
+ * wait for the slow FPGA implementation.
+ */
+
+static hal_error_t modexp(fp_int *msg, fp_int *exp, fp_int *mod, fp_int *res)
+{
+  hal_error_t err = HAL_OK;
+  FP_CHECK(fp_exptmod(msg, exp, mod, res));
+ fail:
+  return err;
+}
+
+#endif /* HAL_RSA_USE_MODEXP */
+
 /*
  * Create blinding factors.  There are various schemes for amortizing
  * the cost of this over multiple RSA operations, at present we don't



More information about the Commits mailing list