aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rsa.c17
1 files changed, 16 insertions, 1 deletions
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.