aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/mp/mp_monty.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/math/mp/mp_monty.cpp')
-rw-r--r--src/lib/math/mp/mp_monty.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lib/math/mp/mp_monty.cpp b/src/lib/math/mp/mp_monty.cpp
index 2599266b0..cc6388f4d 100644
--- a/src/lib/math/mp/mp_monty.cpp
+++ b/src/lib/math/mp/mp_monty.cpp
@@ -20,11 +20,14 @@ namespace Botan {
* Montgomery Reduction Algorithm
*/
void bigint_monty_redc(word z[],
- const word p[], size_t p_size,
- word p_dash, word ws[])
+ const word p[], size_t p_size, word p_dash,
+ word ws[], size_t ws_size)
{
const size_t z_size = 2*(p_size+1);
+ if(ws_size < z_size)
+ throw Invalid_Argument("bigint_monty_redc workspace too small");
+
CT::poison(z, z_size);
CT::poison(p, p_size);
CT::poison(ws, 2*(p_size+1));
@@ -96,24 +99,25 @@ void bigint_monty_redc(word z[],
void bigint_monty_mul(BigInt& z, const BigInt& x, const BigInt& y,
const word p[], size_t p_size, word p_dash,
- word ws[])
+ word ws[], size_t ws_size)
{
- bigint_mul(z, x, y, &ws[0]);
+ bigint_mul(z, x, y, ws, ws_size);
bigint_monty_redc(z.mutable_data(),
p, p_size, p_dash,
- ws);
+ ws, ws_size);
}
void bigint_monty_sqr(BigInt& z, const BigInt& x, const word p[],
- size_t p_size, word p_dash, word ws[])
+ size_t p_size, word p_dash, word ws[], size_t ws_size)
{
- bigint_sqr(z.mutable_data(), z.size(), &ws[0],
- x.data(), x.size(), x.sig_words());
+ bigint_sqr(z.mutable_data(), z.size(),
+ x.data(), x.size(), x.sig_words(),
+ ws, ws_size);
bigint_monty_redc(z.mutable_data(),
p, p_size, p_dash,
- ws);
+ ws, ws_size);
}
}