[Cryptech-Commits] [sw/libhal] 42/58: Add replacement for fp_exptmod() using our ModExp core, so we don't drag in all of TFM's Montgomery just to support the Miller-Rabin test.

git at cryptech.is git at cryptech.is
Tue Jul 7 18:25:26 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 1a719b00709d4a3934aa3d975dc13d0c9fde0e06
Author: Rob Austein <sra at hactrn.net>
Date:   Fri Jun 19 10:08:04 2015 -0400

    Add replacement for fp_exptmod() using our ModExp core, so we don't
    drag in all of TFM's Montgomery just to support the Miller-Rabin test.
---
 rsa.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/rsa.c b/rsa.c
index 28365ae..cda0f7f 100644
--- a/rsa.c
+++ b/rsa.c
@@ -62,7 +62,7 @@
  * to support at compile time.  This should not be a serious problem.
  */
 
-#include "tfm.h"
+#include <tfm.h>
 
 /*
  * Whether we want debug output.
@@ -192,6 +192,21 @@ static hal_error_t modexp(fp_int *msg, fp_int *exp, fp_int *mod, fp_int *res)
 }
 
 /*
+ * Wrapper to let us export our modexp function as a replacement for
+ * TFM's, to avoid dragging all of the TFM montgomery code in when we
+ * use TFM's Miller-Rabin test code.
+ *
+ * This code is here rather than in a separate module because of the
+ * error handling: TFM's error codes aren't really capable of
+ * expressing all the things that could go wrong here.
+ */
+
+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;
+}
+
+/*
  * Create blinding factors.  There are various schemes for amortizing
  * the cost of this over multiple RSA operations, at present we don't
  * try.  Come back to this if it looks like a bottleneck.



More information about the Commits mailing list