aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/mp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-01 19:32:10 +0000
committerlloyd <[email protected]>2012-08-01 19:32:10 +0000
commit7dbcedf896b78db3920368d7dabf2dbc2fa50e09 (patch)
treec6d0228cea1f0a7e7c3cf1e461a5d4ca8dde1040 /src/math/mp
parent3df2a2980adaa8ba598698dc988cbde0433b32f5 (diff)
Remove z_size parameter to bigint_monty_redc because it should always
be 2*(p_size+1). Document that it clears the high part of z. Don't clear the workspace before calling Karatsuba in bigint_mul or bigint_sqr - they clear it every time anyway. Don't bother masking words in the Montgomery_Exponentiator as redc zeros those words. Also don't bother calling z.clear() as the multiply operation does that already.
Diffstat (limited to 'src/math/mp')
-rw-r--r--src/math/mp/mp_core.h10
-rw-r--r--src/math/mp/mp_karat.cpp6
-rw-r--r--src/math/mp/mp_monty.cpp8
3 files changed, 11 insertions, 13 deletions
diff --git a/src/math/mp/mp_core.h b/src/math/mp/mp_core.h
index 579f3fef4..a84b38cdd 100644
--- a/src/math/mp/mp_core.h
+++ b/src/math/mp/mp_core.h
@@ -98,15 +98,17 @@ void bigint_linmul3(word z[], const word x[], size_t x_size, word y);
/**
* Montgomery Reduction
-* @param z integer to reduce (also output in first p_size+1 words)
-* @param z_size size of z (should be >= 2*p_size+1)
+* @param z integer to reduce, of size exactly 2*(p_size+1).
+ Output is in the first p_size+1 words, higher
+ words are set to zero.
* @param p modulus
* @param p_size size of p
* @param p_dash Montgomery value
* @param workspace array of at least 2*(p_size+1) words
*/
-void bigint_monty_redc(word z[], size_t z_size,
- const word p[], size_t p_size, word p_dash,
+void bigint_monty_redc(word z[],
+ const word p[], size_t p_size,
+ word p_dash,
word workspace[]);
/*
diff --git a/src/math/mp/mp_karat.cpp b/src/math/mp/mp_karat.cpp
index 6d9adb4bf..b549a05c8 100644
--- a/src/math/mp/mp_karat.cpp
+++ b/src/math/mp/mp_karat.cpp
@@ -253,10 +253,7 @@ void bigint_mul(word z[], size_t z_size, word workspace[],
const size_t N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw);
if(N)
- {
- clear_mem(workspace, 2*N);
karatsuba_mul(z, x, y, N, workspace);
- }
else
bigint_simple_mul(z, x, x_sw, y, y_sw);
}
@@ -297,10 +294,7 @@ void bigint_sqr(word z[], size_t z_size, word workspace[],
const size_t N = karatsuba_size(z_size, x_size, x_sw);
if(N)
- {
- clear_mem(workspace, 2*N);
karatsuba_sqr(z, x, N, workspace);
- }
else
bigint_simple_sqr(z, x, x_sw);
}
diff --git a/src/math/mp/mp_monty.cpp b/src/math/mp/mp_monty.cpp
index d37fb5844..57a2b51a6 100644
--- a/src/math/mp/mp_monty.cpp
+++ b/src/math/mp/mp_monty.cpp
@@ -18,10 +18,12 @@ extern "C" {
/*
* Montgomery Reduction Algorithm
*/
-void bigint_monty_redc(word z[], size_t z_size,
+void bigint_monty_redc(word z[],
const word p[], size_t p_size,
word p_dash, word ws[])
{
+ const size_t z_size = 2*(p_size+1);
+
const size_t blocks_of_8 = p_size - (p_size % 8);
for(size_t i = 0; i != p_size; ++i)
@@ -76,7 +78,7 @@ void bigint_monty_mul(word z[], size_t z_size,
&x[0], x_size, x_sw,
&y[0], y_size, y_sw);
- bigint_monty_redc(&z[0], z_size,
+ bigint_monty_redc(&z[0],
&p[0], p_size, p_dash,
&ws[0]);
}
@@ -89,7 +91,7 @@ void bigint_monty_sqr(word z[], size_t z_size,
bigint_sqr(&z[0], z_size, &ws[0],
&x[0], x_size, x_sw);
- bigint_monty_redc(&z[0], z_size,
+ bigint_monty_redc(&z[0],
&p[0], p_size, p_dash,
&ws[0]);
}