aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/numbertheory
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 20:32:36 +0000
committerlloyd <[email protected]>2012-05-18 20:32:36 +0000
commitc691561f3198f481c13457433efbccc1c9fcd898 (patch)
treea45ea2c5a30e0cb009fbcb68a61ef39332ff790c /src/math/numbertheory
parentd76700f01c7ecac5633edf75f8d7408b46c5dbac (diff)
Fairly huge update that replaces the old secmem types with std::vector
using a custom allocator. Currently our allocator just does new/delete with a memset before deletion, and the mmap and mlock allocators have been removed.
Diffstat (limited to 'src/math/numbertheory')
-rw-r--r--src/math/numbertheory/dsa_gen.cpp21
-rw-r--r--src/math/numbertheory/make_prm.cpp2
-rw-r--r--src/math/numbertheory/mp_numth.cpp10
-rw-r--r--src/math/numbertheory/numthry.h4
-rw-r--r--src/math/numbertheory/powm_mnt.cpp8
5 files changed, 23 insertions, 22 deletions
diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp
index 612370804..d30a08f1a 100644
--- a/src/math/numbertheory/dsa_gen.cpp
+++ b/src/math/numbertheory/dsa_gen.cpp
@@ -42,7 +42,7 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
Algorithm_Factory& af,
BigInt& p, BigInt& q,
size_t pbits, size_t qbits,
- const MemoryRegion<byte>& seed_c)
+ const std::vector<byte>& seed_c)
{
if(!fips186_3_valid_size(pbits, qbits))
throw Invalid_Argument(
@@ -62,9 +62,9 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
class Seed
{
public:
- Seed(const MemoryRegion<byte>& s) : seed(s) {}
+ Seed(const std::vector<byte>& s) : seed(s) {}
- operator MemoryRegion<byte>& () { return seed; }
+ operator std::vector<byte>& () { return seed; }
Seed& operator++()
{
@@ -74,7 +74,7 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
return (*this);
}
private:
- SecureVector<byte> seed;
+ std::vector<byte> seed;
};
Seed seed(seed_c);
@@ -90,7 +90,7 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
b = (pbits-1) % (HASH_SIZE * 8);
BigInt X;
- SecureVector<byte> V(HASH_SIZE * (n+1));
+ std::vector<byte> V(HASH_SIZE * (n+1));
for(size_t j = 0; j != 4096; ++j)
{
@@ -116,14 +116,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng,
/*
* Generate DSA Primes
*/
-SecureVector<byte> generate_dsa_primes(RandomNumberGenerator& rng,
- Algorithm_Factory& af,
- BigInt& p, BigInt& q,
- size_t pbits, size_t qbits)
+std::vector<byte> generate_dsa_primes(RandomNumberGenerator& rng,
+ Algorithm_Factory& af,
+ BigInt& p, BigInt& q,
+ size_t pbits, size_t qbits)
{
while(true)
{
- SecureVector<byte> seed = rng.random_vec(qbits / 8);
+ std::vector<byte> seed(qbits / 8);
+ rng.randomize(&seed[0], seed.size());
if(generate_dsa_primes(rng, af, p, q, pbits, qbits, seed))
return seed;
diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp
index 1e8d11000..dc94420ab 100644
--- a/src/math/numbertheory/make_prm.cpp
+++ b/src/math/numbertheory/make_prm.cpp
@@ -48,7 +48,7 @@ BigInt random_prime(RandomNumberGenerator& rng,
p += (modulo - p % modulo) + equiv;
const size_t sieve_size = std::min(bits / 2, PRIME_TABLE_SIZE);
- SecureVector<size_t> sieve(sieve_size);
+ secure_vector<u16bit> sieve(sieve_size);
for(size_t j = 0; j != sieve.size(); ++j)
sieve[j] = p % PRIMES[j];
diff --git a/src/math/numbertheory/mp_numth.cpp b/src/math/numbertheory/mp_numth.cpp
index 23623b5f0..b10fe2639 100644
--- a/src/math/numbertheory/mp_numth.cpp
+++ b/src/math/numbertheory/mp_numth.cpp
@@ -20,9 +20,9 @@ BigInt square(const BigInt& x)
const size_t x_sw = x.sig_words();
BigInt z(BigInt::Positive, round_up<size_t>(2*x_sw, 16));
- SecureVector<word> workspace(z.size());
+ secure_vector<word> workspace(z.size());
- bigint_sqr(z.get_reg(), z.size(), workspace,
+ bigint_sqr(z.data(), z.size(), &workspace[0],
x.data(), x.size(), x_sw);
return z;
}
@@ -44,13 +44,13 @@ BigInt mul_add(const BigInt& a, const BigInt& b, const BigInt& c)
const size_t c_sw = c.sig_words();
BigInt r(sign, std::max(a.size() + b.size(), c_sw) + 1);
- SecureVector<word> workspace(r.size());
+ secure_vector<word> workspace(r.size());
- bigint_mul(r.get_reg(), r.size(), workspace,
+ bigint_mul(r.data(), r.size(), &workspace[0],
a.data(), a.size(), a_sw,
b.data(), b.size(), b_sw);
const size_t r_size = std::max(r.sig_words(), c_sw);
- bigint_add2(r.get_reg(), r_size, c.data(), c_sw);
+ bigint_add2(r.data(), r_size, c.data(), c_sw);
return r;
}
diff --git a/src/math/numbertheory/numthry.h b/src/math/numbertheory/numthry.h
index 750fbc78e..d21635f34 100644
--- a/src/math/numbertheory/numthry.h
+++ b/src/math/numbertheory/numthry.h
@@ -189,7 +189,7 @@ class Algorithm_Factory;
* @param qbits how long q will be in bits
* @return random seed used to generate this parameter set
*/
-SecureVector<byte> BOTAN_DLL
+std::vector<byte> BOTAN_DLL
generate_dsa_primes(RandomNumberGenerator& rng,
Algorithm_Factory& af,
BigInt& p_out, BigInt& q_out,
@@ -212,7 +212,7 @@ generate_dsa_primes(RandomNumberGenerator& rng,
Algorithm_Factory& af,
BigInt& p_out, BigInt& q_out,
size_t pbits, size_t qbits,
- const MemoryRegion<byte>& seed);
+ const std::vector<byte>& seed);
/**
* The size of the PRIMES[] array
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index 8993f4ba9..0db5455a7 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -29,8 +29,8 @@ void Montgomery_Exponentiator::set_base(const BigInt& base)
g.resize((1 << window_bits) - 1);
- SecureVector<word> z(2 * (mod_words + 1));
- SecureVector<word> workspace(z.size());
+ secure_vector<word> z(2 * (mod_words + 1));
+ secure_vector<word> workspace(z.size());
g[0] = (base >= modulus) ? (base % modulus) : base;
@@ -69,8 +69,8 @@ BigInt Montgomery_Exponentiator::execute() const
const size_t exp_nibbles = (exp_bits + window_bits - 1) / window_bits;
BigInt x = R_mod;
- SecureVector<word> z(2 * (mod_words + 1));
- SecureVector<word> workspace(2 * (mod_words + 1));
+ secure_vector<word> z(2 * (mod_words + 1));
+ secure_vector<word> workspace(2 * (mod_words + 1));
for(size_t i = exp_nibbles; i > 0; --i)
{