diff options
author | lloyd <[email protected]> | 2010-01-21 16:36:12 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-01-21 16:36:12 +0000 |
commit | 412a13fc607a57bd9986155d247353ba8e5fb203 (patch) | |
tree | cbdf63aaa7e9f28a748dedda286e79a138573f74 /src/math | |
parent | 41bed2fa0c4d96faf805cd33850166972dcac114 (diff) | |
parent | 9b82bb5a720f32e3e7878550310b1151cac188b8 (diff) |
propagate from branch 'net.randombit.botan' (head 12382647ef0a28fcb11c824c77b670cc88a4f721)
to branch 'net.randombit.botan.c++0x' (head b586a3286d2c4d547ad3add5af9df1455bf4b87b)
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/bigint/bigint.cpp | 21 | ||||
-rw-r--r-- | src/math/bigint/bigint.h | 19 | ||||
-rw-r--r-- | src/math/gfpmath/curve_gfp.cpp | 28 | ||||
-rw-r--r-- | src/math/gfpmath/curve_gfp.h | 16 | ||||
-rw-r--r-- | src/math/gfpmath/gfp_element.cpp | 6 | ||||
-rw-r--r-- | src/math/gfpmath/gfp_element.h | 17 | ||||
-rw-r--r-- | src/math/gfpmath/info.txt | 2 | ||||
-rw-r--r-- | src/math/gfpmath/point_gfp.cpp | 16 | ||||
-rw-r--r-- | src/math/gfpmath/point_gfp.h | 10 | ||||
-rw-r--r-- | src/math/numbertheory/dsa_gen.cpp | 8 | ||||
-rw-r--r-- | src/math/numbertheory/make_prm.cpp | 4 | ||||
-rw-r--r-- | src/math/numbertheory/numthry.cpp | 2 |
12 files changed, 86 insertions, 63 deletions
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 70bb11a83..225059e47 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -40,7 +40,7 @@ BigInt::BigInt(Sign s, u32bit size) } /* -* Construct a BigInt from a "raw" BigInt +* Copy constructor */ BigInt::BigInt(const BigInt& b) { @@ -100,6 +100,25 @@ BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits) randomize(rng, bits); } +/** +* Move constructor +*/ +BigInt::BigInt(BigInt&& other) + { + std::swap(*this, other); + } + +/** +* Move assignment +*/ +BigInt& BigInt::operator=(BigInt&& other) + { + if(this != &other) + std::swap(*this, other); + + return (*this); + } + /* * Swap this BigInt with another */ diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index 55ccf7aae..2612850c3 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -425,10 +425,14 @@ class BOTAN_DLL BigInt BigInt(u64bit n); /** - * Copy-Constructor: clone given BigInt - * @param bigint the BigInt to clone + * Copy constructor */ - BigInt(const BigInt& bigint); + BigInt(const BigInt& other); + + /** + * Assignment operator + */ + BigInt& operator=(const BigInt&) = default; /** * Create BigInt from a string. @@ -471,6 +475,15 @@ class BOTAN_DLL BigInt */ BigInt(NumberType type, u32bit n); + /** + * Move constructor + */ + BigInt(BigInt&& other); + + /** + * Move assignment + */ + BigInt& operator=(BigInt&& other); private: SecureVector<word> reg; Sign signedness; diff --git a/src/math/gfpmath/curve_gfp.cpp b/src/math/gfpmath/curve_gfp.cpp index 9a3ffd482..d88146dd5 100644 --- a/src/math/gfpmath/curve_gfp.cpp +++ b/src/math/gfpmath/curve_gfp.cpp @@ -14,7 +14,7 @@ namespace Botan { -void CurveGFp::set_shrd_mod(const std::tr1::shared_ptr<GFpModulus> mod) +void CurveGFp::set_shrd_mod(const std::shared_ptr<GFpModulus> mod) { mp_mod = mod; mA.turn_off_sp_red_mul();// m.m. is not needed, must be trf. back @@ -34,7 +34,7 @@ CurveGFp::CurveGFp(const GFpElement& a, const GFpElement& b, { throw Invalid_Argument("could not construct curve: moduli of arguments differ"); } - std::tr1::shared_ptr<GFpModulus> p_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(p)); + std::shared_ptr<GFpModulus> p_mod = std::shared_ptr<GFpModulus>(new GFpModulus(p)); // the above is the creation of the GFpModuls object which will be shared point-wide // (in the context of a point of course) set_shrd_mod(p_mod); @@ -44,21 +44,21 @@ CurveGFp::CurveGFp(const CurveGFp& other) : mA(other.get_a()), mB(other.get_b()) { - mp_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(*other.mp_mod)); + mp_mod = std::shared_ptr<GFpModulus>(new GFpModulus(*other.mp_mod)); assert(mp_mod->p_equal_to(mA.get_p())); assert(mp_mod->p_equal_to(mB.get_p())); set_shrd_mod(mp_mod); if(other.mp_mres_a.get()) { - mp_mres_a = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_a)); + mp_mres_a = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_a)); } if(other.mp_mres_b.get()) { - mp_mres_b = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_b)); + mp_mres_b = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_b)); } if(other.mp_mres_one.get()) { - mp_mres_one = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_one)); + mp_mres_one = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_one)); } } @@ -72,21 +72,21 @@ const CurveGFp& CurveGFp::operator=(const CurveGFp& other) mA.swap(a_tmp); mB.swap(b_tmp); - std::tr1::shared_ptr<GFpModulus> p_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(*other.mp_mod)); + std::shared_ptr<GFpModulus> p_mod = std::shared_ptr<GFpModulus>(new GFpModulus(*other.mp_mod)); set_shrd_mod(p_mod); // exception safety note: no problem if we have a throw from here on... if(other.mp_mres_a.get()) { - mp_mres_a = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_a)); + mp_mres_a = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_a)); } if(other.mp_mres_b.get()) { - mp_mres_b = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_b)); + mp_mres_b = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_b)); } if(other.mp_mres_one.get()) { - mp_mres_one = std::tr1::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_one)); + mp_mres_one = std::shared_ptr<GFpElement>(new GFpElement(*other.mp_mres_one)); } return *this; } @@ -123,7 +123,7 @@ GFpElement const CurveGFp::get_mres_a() const { if(mp_mres_a.get() == 0) { - mp_mres_a = std::tr1::shared_ptr<GFpElement>(new GFpElement(mA)); + mp_mres_a = std::shared_ptr<GFpElement>(new GFpElement(mA)); mp_mres_a->turn_on_sp_red_mul(); mp_mres_a->get_mres(); } @@ -134,18 +134,18 @@ GFpElement const CurveGFp::get_mres_b() const { if(mp_mres_b.get() == 0) { - mp_mres_b = std::tr1::shared_ptr<GFpElement>(new GFpElement(mB)); + mp_mres_b = std::shared_ptr<GFpElement>(new GFpElement(mB)); mp_mres_b->turn_on_sp_red_mul(); mp_mres_b->get_mres(); } return GFpElement(*mp_mres_b); } -std::tr1::shared_ptr<GFpElement const> const CurveGFp::get_mres_one() const +std::shared_ptr<GFpElement const> const CurveGFp::get_mres_one() const { if(mp_mres_one.get() == 0) { - mp_mres_one = std::tr1::shared_ptr<GFpElement>(new GFpElement(mp_mod->get_p(), 1)); + mp_mres_one = std::shared_ptr<GFpElement>(new GFpElement(mp_mod->get_p(), 1)); mp_mres_one->turn_on_sp_red_mul(); mp_mres_one->get_mres(); } diff --git a/src/math/gfpmath/curve_gfp.h b/src/math/gfpmath/curve_gfp.h index 53bbc1f3c..5b0ec0558 100644 --- a/src/math/gfpmath/curve_gfp.h +++ b/src/math/gfpmath/curve_gfp.h @@ -52,7 +52,7 @@ class BOTAN_DLL CurveGFp * @param mod a shared pointer to a GFpModulus object suitable for * *this. */ - void set_shrd_mod(const std::tr1::shared_ptr<GFpModulus> mod); + void set_shrd_mod(const std::shared_ptr<GFpModulus> mod); // getters @@ -94,14 +94,14 @@ class BOTAN_DLL CurveGFp * function. * @result the GFpElement 1, transformed to its m-residue */ - std::tr1::shared_ptr<GFpElement const> const get_mres_one() const; + std::shared_ptr<GFpElement const> const get_mres_one() const; /** * Get prime modulus of the field of the curve * @result prime modulus of the field of the curve */ BigInt const get_p() const; - /*inline std::tr1::shared_ptr<BigInt> const get_ptr_p() const + /*inline std::shared_ptr<BigInt> const get_ptr_p() const { return mp_p; }*/ @@ -115,7 +115,7 @@ class BOTAN_DLL CurveGFp * pointers to a GFpModulus over different threads! * @result a shared pointer to a GFpModulus object */ - inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const + inline std::shared_ptr<GFpModulus> const get_ptr_mod() const { return mp_mod; } @@ -127,12 +127,12 @@ class BOTAN_DLL CurveGFp void swap(CurveGFp& other); private: - std::tr1::shared_ptr<GFpModulus> mp_mod; + std::shared_ptr<GFpModulus> mp_mod; GFpElement mA; GFpElement mB; - mutable std::tr1::shared_ptr<GFpElement> mp_mres_a; - mutable std::tr1::shared_ptr<GFpElement> mp_mres_b; - mutable std::tr1::shared_ptr<GFpElement> mp_mres_one; + mutable std::shared_ptr<GFpElement> mp_mres_a; + mutable std::shared_ptr<GFpElement> mp_mres_b; + mutable std::shared_ptr<GFpElement> mp_mres_one; }; // relational operators diff --git a/src/math/gfpmath/gfp_element.cpp b/src/math/gfpmath/gfp_element.cpp index 233f2e4cd..3f028f34f 100644 --- a/src/math/gfpmath/gfp_element.cpp +++ b/src/math/gfpmath/gfp_element.cpp @@ -172,13 +172,13 @@ GFpElement::GFpElement(const BigInt& p, const BigInt& value, bool use_montgm) m_is_trf(false) { assert(mp_mod.get() == 0); - mp_mod = std::tr1::shared_ptr<GFpModulus>(new GFpModulus(p)); + mp_mod = std::shared_ptr<GFpModulus>(new GFpModulus(p)); assert(mp_mod->m_p_dash == 0); if(m_use_montgm) ensure_montgm_precomp(); } -GFpElement::GFpElement(std::tr1::shared_ptr<GFpModulus> const mod, const BigInt& value, bool use_montgm) +GFpElement::GFpElement(std::shared_ptr<GFpModulus> const mod, const BigInt& value, bool use_montgm) : mp_mod(), m_value(value % mod->m_p), m_use_montgm(use_montgm), @@ -245,7 +245,7 @@ void GFpElement::ensure_montgm_precomp() const } -void GFpElement::set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const p_mod) +void GFpElement::set_shrd_mod(std::shared_ptr<GFpModulus> const p_mod) { mp_mod = p_mod; } diff --git a/src/math/gfpmath/gfp_element.h b/src/math/gfpmath/gfp_element.h index 7a8644fee..a4d9ac250 100644 --- a/src/math/gfpmath/gfp_element.h +++ b/src/math/gfpmath/gfp_element.h @@ -12,14 +12,7 @@ #include <botan/bigint.h> #include <botan/gfp_modulus.h> #include <iosfwd> - -#if defined(BOTAN_USE_STD_TR1) - #include <tr1/memory> -#elif defined(BOTAN_USE_BOOST_TR1) - #include <boost/tr1/memory.hpp> -#else - #error "Please choose a TR1 implementation in build.h" -#endif +#include <memory> namespace Botan { @@ -59,7 +52,7 @@ class BOTAN_DLL GFpElement * @param value the element value * @param use_montgm whether this object will use Montgomery multiplication */ - explicit GFpElement(std::tr1::shared_ptr<GFpModulus> const mod, + explicit GFpElement(std::shared_ptr<GFpModulus> const mod, const BigInt& value, bool use_mongm = false); /** @@ -170,7 +163,7 @@ class BOTAN_DLL GFpElement * the shared GFpModulus objects! * @result the shared pointer to the GFpModulus of *this */ - inline std::tr1::shared_ptr<GFpModulus> const get_ptr_mod() const + inline std::shared_ptr<GFpModulus> const get_ptr_mod() const { return mp_mod; } @@ -183,7 +176,7 @@ class BOTAN_DLL GFpElement * the shared GFpModulus objects! * @param mod a shared pointer to a GFpModulus that will be held in *this */ - void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> const mod); + void set_shrd_mod(std::shared_ptr<GFpModulus> const mod); /** * Tells whether this GFpElement is currently transformed to it´ m-residue, @@ -237,7 +230,7 @@ class BOTAN_DLL GFpElement void trf_to_mres() const; void trf_to_ordres() const; - std::tr1::shared_ptr<GFpModulus> mp_mod; + std::shared_ptr<GFpModulus> mp_mod; mutable BigInt m_value; // ordinary residue or m-residue respectively mutable BigInt workspace; diff --git a/src/math/gfpmath/info.txt b/src/math/gfpmath/info.txt index a02dbc044..b7b430805 100644 --- a/src/math/gfpmath/info.txt +++ b/src/math/gfpmath/info.txt @@ -1,7 +1,5 @@ define BIGINT_GFP -uses_tr1 yes - <header:public> curve_gfp.h gfp_element.h diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp index 4203a3db3..050fd0f50 100644 --- a/src/math/gfpmath/point_gfp.cpp +++ b/src/math/gfpmath/point_gfp.cpp @@ -108,7 +108,7 @@ const PointGFp& PointGFp::assign_within_same_curve(PointGFp const& other) return *this; } -void PointGFp::set_shrd_mod(std::tr1::shared_ptr<GFpModulus> p_mod) +void PointGFp::set_shrd_mod(std::shared_ptr<GFpModulus> p_mod) { mX.set_shrd_mod(p_mod); mY.set_shrd_mod(p_mod); @@ -132,7 +132,7 @@ void PointGFp::ensure_worksp() const } } - mp_worksp_gfp_el = std::tr1::shared_ptr<std::vector<GFpElement> >(new std::vector<GFpElement>); + mp_worksp_gfp_el = std::shared_ptr<std::vector<GFpElement> >(new std::vector<GFpElement>); mp_worksp_gfp_el->reserve(9); for (u32bit i=0; i<GFPEL_WKSP_SIZE; i++) { @@ -336,8 +336,8 @@ PointGFp& PointGFp::mult_this_secure(const BigInt& scalar, // use montgomery mult. in this operation this->turn_on_sp_red_mul(); - std::tr1::shared_ptr<PointGFp> H(new PointGFp(this->mC)); - std::tr1::shared_ptr<PointGFp> tmp; // used for AADA + std::shared_ptr<PointGFp> H(new PointGFp(this->mC)); + std::shared_ptr<PointGFp> tmp; // used for AADA PointGFp P(*this); BigInt m(scalar); @@ -476,15 +476,15 @@ PointGFp& PointGFp::operator*=(const BigInt& scalar) return *this; } -inline std::tr1::shared_ptr<PointGFp> PointGFp::mult_loop(int l, +inline std::shared_ptr<PointGFp> PointGFp::mult_loop(int l, const BigInt& m, - std::tr1::shared_ptr<PointGFp> H, - std::tr1::shared_ptr<PointGFp> tmp, + std::shared_ptr<PointGFp> H, + std::shared_ptr<PointGFp> tmp, const PointGFp& P) { //assert(l >= (int)m.bits()- 1); tmp = H; - std::tr1::shared_ptr<PointGFp> to_add(new PointGFp(P)); // we just need some point + std::shared_ptr<PointGFp> to_add(new PointGFp(P)); // we just need some point // so that we can use op= // inside the loop for (int i=l; i >=0; i--) diff --git a/src/math/gfpmath/point_gfp.h b/src/math/gfpmath/point_gfp.h index 0c7bb8428..10fc404bf 100644 --- a/src/math/gfpmath/point_gfp.h +++ b/src/math/gfpmath/point_gfp.h @@ -232,7 +232,7 @@ class BOTAN_DLL PointGFp * @param mod a shared pointer to a GFpModulus that will * be held in the members *this */ - void set_shrd_mod(std::tr1::shared_ptr<GFpModulus> p_mod); + void set_shrd_mod(std::shared_ptr<GFpModulus> p_mod); static GFpElement decompress(bool yMod2, GFpElement const& x, const CurveGFp& curve); @@ -240,9 +240,9 @@ class BOTAN_DLL PointGFp static const u32bit GFPEL_WKSP_SIZE = 9; void ensure_worksp() const; - inline std::tr1::shared_ptr<PointGFp> mult_loop(int l, const BigInt& m, - std::tr1::shared_ptr<PointGFp> H, - std::tr1::shared_ptr<PointGFp> tmp, + inline std::shared_ptr<PointGFp> mult_loop(int l, const BigInt& m, + std::shared_ptr<PointGFp> H, + std::shared_ptr<PointGFp> tmp, const PointGFp& P); CurveGFp mC; @@ -255,7 +255,7 @@ class BOTAN_DLL PointGFp mutable bool mZpow2_set; mutable bool mZpow3_set; mutable bool mAZpow4_set; - mutable std::tr1::shared_ptr<std::vector<GFpElement> > mp_worksp_gfp_el; + mutable std::shared_ptr<std::vector<GFpElement> > mp_worksp_gfp_el; }; diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index 83646e50e..39a7cf5fa 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -47,15 +47,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, if(!fips186_3_valid_size(pbits, qbits)) throw Invalid_Argument( "FIPS 186-3 does not allow DSA domain parameters of " + - to_string(pbits) + "/" + to_string(qbits) + " bits long"); + std::to_string(pbits) + "/" + std::to_string(qbits) + " bits long"); if(seed_c.size() * 8 < qbits) throw Invalid_Argument( - "Generating a DSA parameter set with a " + to_string(qbits) + + "Generating a DSA parameter set with a " + std::to_string(qbits) + "long q requires a seed at least as many bits long"); - std::auto_ptr<HashFunction> hash( - af.make_hash_function("SHA-" + to_string(qbits))); + std::unique_ptr<HashFunction> hash( + af.make_hash_function("SHA-" + std::to_string(qbits))); const u32bit HASH_SIZE = hash->OUTPUT_LENGTH; diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp index b136b6d25..3eb01cd42 100644 --- a/src/math/numbertheory/make_prm.cpp +++ b/src/math/numbertheory/make_prm.cpp @@ -20,7 +20,7 @@ BigInt random_prime(RandomNumberGenerator& rng, { if(bits <= 1) throw Invalid_Argument("random_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); else if(bits == 2) return ((rng.next_byte() % 2) ? 2 : 3); else if(bits == 3) @@ -85,7 +85,7 @@ BigInt random_safe_prime(RandomNumberGenerator& rng, u32bit bits) { if(bits <= 64) throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); BigInt p; do diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp index 0740ea21b..760250712 100644 --- a/src/math/numbertheory/numthry.cpp +++ b/src/math/numbertheory/numthry.cpp @@ -20,7 +20,7 @@ u32bit miller_rabin_test_iterations(u32bit bits, bool verify) { struct mapping { u32bit bits; u32bit verify_iter; u32bit check_iter; }; - static const mapping tests[] = { + const mapping tests[] = { { 50, 55, 25 }, { 100, 38, 22 }, { 160, 32, 18 }, |