aboutsummaryrefslogtreecommitdiffstats
path: root/src/mp_sqr.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-19 12:42:23 +0000
committerlloyd <[email protected]>2006-08-19 12:42:23 +0000
commit70db176e715f4fc143ccd1ff75984fdf7c0845cd (patch)
tree792d75d784f60de69e0013856289630c0833a19b /src/mp_sqr.cpp
parentf119968c6465a0d1b953e209f6e3db180a46883c (diff)
Move bigint_simple_mul into mp_mul.cpp, since that is the only place it
was used. Make a variant of bigint_simple_mul, bigint_simple_sqr, for mp_sqr.cpp
Diffstat (limited to 'src/mp_sqr.cpp')
-rw-r--r--src/mp_sqr.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/mp_sqr.cpp b/src/mp_sqr.cpp
index 934a90c5a..57b4695ee 100644
--- a/src/mp_sqr.cpp
+++ b/src/mp_sqr.cpp
@@ -11,6 +11,17 @@ namespace Botan {
namespace {
/*************************************************
+* Simple O(N^2) Squaring *
+*************************************************/
+void bigint_simple_sqr(word z[], const word x[], u32bit x_size)
+ {
+ clear_mem(z, 2*x_size);
+
+ for(u32bit j = 0; j != x_size; ++j)
+ z[j+x_size] = bigint_mul_add_words(z + j, x, x_size, x[j]);
+ }
+
+/*************************************************
* Karatsuba Squaring Operation *
*************************************************/
void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
@@ -22,7 +33,7 @@ void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
else if(N == 8)
bigint_comba_sqr8(z, x);
else if(N < KARATSUBA_SQR_LOWER_SIZE || N % 2)
- bigint_simple_mul(z, x, N, x, N);
+ bigint_simple_sqr(z, x, N);
else
{
const u32bit N2 = N / 2;
@@ -103,7 +114,7 @@ void handle_small_sqr(word z[], u32bit z_size,
else if(x_sw <= 8 && x_size >= 8 && z_size >= 16)
bigint_comba_sqr8(z, x);
else
- bigint_simple_mul(z, x, x_sw, x, x_sw);
+ bigint_simple_sqr(z, x, x_sw);
}
}
@@ -128,7 +139,7 @@ void bigint_sqr(word z[], u32bit z_size, word workspace[],
karatsuba_sqr(z, x, N, workspace);
}
else
- bigint_simple_mul(z, x, x_sw, x, x_sw);
+ bigint_simple_sqr(z, x, x_sw);
}
}