aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mp_asm.cpp33
-rw-r--r--src/mp_monty.cpp49
2 files changed, 49 insertions, 33 deletions
diff --git a/src/mp_asm.cpp b/src/mp_asm.cpp
index 02f75f281..e45a92e2c 100644
--- a/src/mp_asm.cpp
+++ b/src/mp_asm.cpp
@@ -196,39 +196,6 @@ void bigint_simple_mul(word z[], const word x[], u32bit x_size,
}
}
-/*************************************************
-* Montgomery Reduction Algorithm *
-*************************************************/
-void bigint_monty_redc(word z[], u32bit z_size,
- const word x[], u32bit x_size, word u)
- {
- for(u32bit j = 0; j != x_size; ++j)
- {
- word* z_j = z + j;
-
- const word y = z_j[0] * u;
- word carry = 0;
-
- const u32bit blocks = x_size - (x_size % 8);
-
- for(u32bit k = 0; k != blocks; k += 8)
- carry = word8_madd3(z_j + k, x + k, y, carry);
-
- for(u32bit k = blocks; k != x_size; ++k)
- z_j[k] = word_madd3(x[k], y, z_j[k], carry, &carry);
-
- word carry2 = 0;
- z_j[x_size] = word_add(z_j[x_size], carry, &carry2);
- carry = carry2;
-
- for(u32bit k = x_size + 1; carry && k != z_size - j; ++k)
- {
- ++z_j[k];
- carry = !z_j[k];
- }
- }
- }
-
}
}
diff --git a/src/mp_monty.cpp b/src/mp_monty.cpp
new file mode 100644
index 000000000..03f6f966b
--- /dev/null
+++ b/src/mp_monty.cpp
@@ -0,0 +1,49 @@
+/*************************************************
+* Montgomery Reduction Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/mp_asm.h>
+#include <botan/mp_asmi.h>
+#include <botan/mp_core.h>
+
+namespace Botan {
+
+extern "C" {
+
+/*************************************************
+* Montgomery Reduction Algorithm *
+*************************************************/
+void bigint_monty_redc(word z[], u32bit z_size,
+ const word x[], u32bit x_size, word u)
+ {
+ for(u32bit j = 0; j != x_size; ++j)
+ {
+ word* z_j = z + j;
+
+ const word y = z_j[0] * u;
+ word carry = 0;
+
+ const u32bit blocks = x_size - (x_size % 8);
+
+ for(u32bit k = 0; k != blocks; k += 8)
+ carry = word8_madd3(z_j + k, x + k, y, carry);
+
+ for(u32bit k = blocks; k != x_size; ++k)
+ z_j[k] = word_madd3(x[k], y, z_j[k], carry, &carry);
+
+ word carry2 = 0;
+ z_j[x_size] = word_add(z_j[x_size], carry, &carry2);
+ carry = carry2;
+
+ for(u32bit k = x_size + 1; carry && k != z_size - j; ++k)
+ {
+ ++z_j[k];
+ carry = !z_j[k];
+ }
+ }
+ }
+
+}
+
+}