aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/math/numbertheory/pow_mod.cpp33
-rw-r--r--src/lib/math/numbertheory/pow_mod.h4
2 files changed, 11 insertions, 26 deletions
diff --git a/src/lib/math/numbertheory/pow_mod.cpp b/src/lib/math/numbertheory/pow_mod.cpp
index e4fed9925..1a03767b8 100644
--- a/src/lib/math/numbertheory/pow_mod.cpp
+++ b/src/lib/math/numbertheory/pow_mod.cpp
@@ -15,7 +15,6 @@ namespace Botan {
*/
Power_Mod::Power_Mod(const BigInt& n, Usage_Hints hints, bool disable_monty)
{
- m_core = nullptr;
set_modulus(n, hints, disable_monty);
}
@@ -24,9 +23,8 @@ Power_Mod::Power_Mod(const BigInt& n, Usage_Hints hints, bool disable_monty)
*/
Power_Mod::Power_Mod(const Power_Mod& other)
{
- m_core = nullptr;
- if(other.m_core)
- m_core = other.m_core->copy();
+ if(other.m_core.get())
+ m_core.reset(other.m_core->copy());
}
/*
@@ -36,42 +34,29 @@ Power_Mod& Power_Mod::operator=(const Power_Mod& other)
{
if(this != &other)
{
- delete m_core;
- m_core = nullptr;
if(other.m_core)
- {
- m_core = other.m_core->copy();
- }
+ m_core.reset(other.m_core->copy());
+ else
+ m_core.reset();
}
return (*this);
}
/*
-* Power_Mod Destructor
-*/
-Power_Mod::~Power_Mod()
- {
- delete m_core;
- m_core = nullptr;
- }
-
-/*
* Set the modulus
*/
void Power_Mod::set_modulus(const BigInt& n, Usage_Hints hints, bool disable_monty) const
{
// Allow set_modulus(0) to mean "drop old state"
- delete m_core;
- m_core = nullptr;
+ m_core.reset();
if(n != 0)
{
if(n.is_odd() && disable_monty == false)
- m_core = new Montgomery_Exponentiator(n, hints);
-
- if(!m_core)
- m_core = new Fixed_Window_Exponentiator(n, hints);
+ m_core.reset(new Montgomery_Exponentiator(n, hints));
+ else
+ m_core.reset(new Fixed_Window_Exponentiator(n, hints));
}
}
diff --git a/src/lib/math/numbertheory/pow_mod.h b/src/lib/math/numbertheory/pow_mod.h
index 7613c2ddf..cca99b714 100644
--- a/src/lib/math/numbertheory/pow_mod.h
+++ b/src/lib/math/numbertheory/pow_mod.h
@@ -93,9 +93,9 @@ class BOTAN_PUBLIC_API(2,0) Power_Mod
Usage_Hints hints = NO_HINTS,
bool disable_montgomery_arith = false);
Power_Mod(const Power_Mod&);
- virtual ~Power_Mod();
+ virtual ~Power_Mod() {}
private:
- mutable Modular_Exponentiator* m_core;
+ mutable std::unique_ptr<Modular_Exponentiator> m_core;
};
/**