aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/numbertheory
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-07 23:40:31 +0000
committerlloyd <[email protected]>2010-09-07 23:40:31 +0000
commit197f7cd4f744ae8246832343dc514296632554b2 (patch)
tree63963dfab01e29ce32be4c1d43e62506d9f0246d /src/math/numbertheory
parent5f83d344e49a6d62cd8989d9fb8f8ca80ed48fc1 (diff)
Big, invasive but mostly automated change, with a further attempt at
harmonising MemoryRegion with std::vector: The MemoryRegion::clear() function would zeroise the buffer, but keep the memory allocated and the size unchanged. This is very different from STL's clear(), which is basically the equivalent to what is called destroy() in MemoryRegion. So to be able to replace MemoryRegion with a std::vector, we have to rename destroy() to clear() and we have to expose the current functionality of clear() in some other way, since vector doesn't support this operation. Do so by adding a global function named zeroise() which takes a MemoryRegion which is zeroed. Remove clear() to ensure all callers are updated.
Diffstat (limited to 'src/math/numbertheory')
-rw-r--r--src/math/numbertheory/point_gfp.cpp4
-rw-r--r--src/math/numbertheory/powm_mnt.cpp8
2 files changed, 6 insertions, 6 deletions
diff --git a/src/math/numbertheory/point_gfp.cpp b/src/math/numbertheory/point_gfp.cpp
index 6e62a9a13..93e3392ea 100644
--- a/src/math/numbertheory/point_gfp.cpp
+++ b/src/math/numbertheory/point_gfp.cpp
@@ -46,7 +46,7 @@ void PointGFp::monty_mult(BigInt& z,
const u32bit p_size = curve.get_p_words();
const word p_dash = curve.get_p_dash();
- workspace.clear();
+ zeroise(workspace);
bigint_mul(workspace, workspace.size(), 0,
x.data(), x.size(), x.sig_words(),
@@ -73,7 +73,7 @@ void PointGFp::monty_sqr(BigInt& z, const BigInt& x,
const u32bit p_size = curve.get_p_words();
const word p_dash = curve.get_p_dash();
- workspace.clear();
+ zeroise(workspace);
bigint_sqr(workspace, workspace.size(), 0,
x.data(), x.size(), x.sig_words());
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index cce142020..80582eaa8 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -66,7 +66,7 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
const BigInt& y = g[j-1];
const u32bit y_sig = y.sig_words();
- z.clear();
+ zeroise(z);
bigint_mul(z.begin(), z.size(), workspace,
x.data(), x.size(), x_sig,
y.data(), y.size(), y_sig);
@@ -90,7 +90,7 @@ BigInt Montgomery_Exponentiator::execute() const
{
for(u32bit k = 0; k != window_bits; ++k)
{
- z.clear();
+ zeroise(z);
bigint_sqr(z.begin(), z.size(), workspace,
x.data(), x.size(), x.sig_words());
@@ -102,7 +102,7 @@ BigInt Montgomery_Exponentiator::execute() const
{
const BigInt& y = g[nibble-1];
- z.clear();
+ zeroise(z);
bigint_mul(z.begin(), z.size(), workspace,
x.data(), x.size(), x.sig_words(),
y.data(), y.size(), y.sig_words());
@@ -111,7 +111,7 @@ BigInt Montgomery_Exponentiator::execute() const
}
}
- z.clear();
+ zeroise(z);
z.copy(x.data(), x.size());
montgomery_reduce(x, z, modulus, mod_words, mod_prime);